Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/24/07 00:00
Read: times


 
#147345 - Here goes the code. Thanks for all help
Responding to: ???'s previous message
Hi again Hans, want to thank you again for help you and all other people are giving me.

; Firmware Version 1.4
;
;
; -Changes since 1.3
; Fixed sending values twice
; Shows Firmware Version instead of Please Wait
; Jump Initialization screen if CTRL 28 = 255
; Enter Presentation mode if CTRL 28 and 29 = 255
;


WRA             EQU P3.4
INTR            EQU P3.5
RDA             EQU P3.3

DB4     EQU   P0.4
DB5     EQU   P0.5
DB6     EQU   P0.6
DB7     EQU   P0.7
EN      EQU   P0.3 ;PIN6
RS      EQU   P0.1 ;PIN4
RW      EQU   P0.2 ;PIN5
DATAP   EQU   P0

TL              EQU 07Ah        ; Endereços das variaveis
TH              EQU 07Bh
TS              EQU 07Ch
TP              EQU 07Dh
V0              EQU 07Eh
V1              EQU 07Fh        ; DONT USE OVER THIS - SFR ADDRESS START


;P3.4 <-->WR(to start convert analog - binary (0804)we must have WR 0->1)
;P3.5 <-->INTR (=0 to and convert) 
;P3.3 <-->RD (RD 1->0 to read data from ADC)
;P2 <-->D0-D7 (out put) 
;-----------------------------------------------------------;

START:  MOV PCON,#0
        MOV TMOD,#00100010B ;Set Timer1 Mode for 8bit autoreload (T1M1=1)
        MOV TL1,#255        ;Set load/reload
        MOV TH1,#255        ;
        SETB TR1
        MOV SCON,#01000010B
        MOV P2,#255         ; to receive data from ADC
        MOV P1,#00000000b   ; Mux Input 0
        MOV R0,#080h
        MOV R2,#0
        MOV R3,#0
        
        MOV P1,R2
        
        
        MOV TL,#0
        MOV TH,#0
        CALL DELAY
        
        CALL WAIT_LCD
        CALL INIT_LCD

        MOV A,#01000000B    ;custom char 0
        LCALL WRITE_2_NIBBLES
        LCALL WAIT_LCD
        
        MOV DPTR,#CUSTCHARS ;SET CUSTOM CHARS
        CALL LCD_WRITE_STRING
        
        CALL CLEAR_LCD
        
        
        ;Jump Loading screen if CTRL 28 = 255
        MOV R2,#28
        CALL READADC
        CJNE A,#255,Loading
        
        MOV DPTR,#FMIDI
        CALL LCD_WRITE_STRING

        MOV   A,#0C0h       ;SECOND LINE
        LCALL WRITE_2_NIBBLES
        LCALL WAIT_LCD
        
        MOV DPTR,#FCHICONTROLLER
        CALL LCD_WRITE_STRING


        ;Show Presentation if CTRL 29 = 255
PresIn: MOV R2,#29
        CALL READADC
        CJNE A,#255,READ0
        CALL Presentation
        
        CALL CLEAR_LCD
        
        MOV DPTR,#FMIDI
        CALL LCD_WRITE_STRING

        MOV   A,#0C0h       ;SECOND LINE
        LCALL WRITE_2_NIBBLES
        LCALL WAIT_LCD
        
        MOV DPTR,#FCHICONTROLLER
        CALL LCD_WRITE_STRING
        
        JMP READ0
        
        
        
        
Loading:MOV DPTR,#FINITIALIZING
        CALL LCD_WRITE_STRING

        MOV   A,#0C0h       ;SECOND LINE
        LCALL WRITE_2_NIBBLES
        LCALL WAIT_LCD
        
        MOV DPTR,#FFIRMWAREVer
        CALL LCD_WRITE_STRING

        MOV TS,#20
        CALL LDELAY
        CALL CLEAR_LCD
        
        MOV DPTR,#FMIDI
        CALL LCD_WRITE_STRING

        MOV   A,#0C0h       ;SECOND LINE
        LCALL WRITE_2_NIBBLES
        LCALL WAIT_LCD
        
        MOV DPTR,#FCHICONTROLLER
        CALL LCD_WRITE_STRING

        MOV TS,#30
        CALL LDELAY
        ;CALL CLEAR_LCD


READ0:  CALL READADC        ; Read ADC
        MOV TH,A
        MOV TP,@R0          ; Remember previous value
        CLR C
        SUBB A,TP           ; Current - Previous
        JNC ABSEND          ; If carry: result was negative, CPL IT!
        CPL A
        INC A


ABSEND: CJNE A,#2,TRESADC   ; Compare change to deadzone
TRESADC:JC INCI             ; less than value. ignore
        MOV A,TH
SEND0:  MOV @R0,A           ; Update ram value with new one
        CALL SEND
        
        
INCI:   MOV A,R3            ; INCREMENT FOR NEXT READ
        MOV R2,A            ; V
        MOV R0,A            ; V
        MOV A,#080h
        ORL A,R0
        MOV R0,A
        INC R3              ; V
        ;CJNE R3,#20,ISO     ; #N = NUMBER OF VALUES TO BE READ
        CJNE R3,#30,ISO     ; #N = NUMBER OF VALUES TO BE READ
        ;MOV R3,#8           ; V
        MOV R3,#0           ; V
ISO:    JMP READ0           ; START OVER




READADC:MOV P1,R2           ; Set mux Input
        MOV TL,#1
        MOV TH,#1
        CALL DELAY
        CLR WRA
        SETB WRA            ; dat WR = 1 to start convert
        JB INTR,$           ; wait to end convert 
        CLR RDA             ; end convert and allow read data from ADC
        MOV A,P2            ; read data onto A register
        MOV P1,R3           ; Set next input
        SETB RDA
        RET
        
SEND:   JNB TI,$            ; If diff send midi
        CLR TI
        MOV SBUF,#0B0H      ; Control Change Channel 0
        
        CLR C               ; Midi adjust (MSB must be 0)
        RRC A               ; Midi adjust
        MOV TS,A
        
        MOV   A,#080h       ;FIRST LINE
        LCALL WRITE_2_NIBBLES
        LCALL WAIT_LCD
        MOV A,#'O'
        CALL WRITE_TEXT
        MOV A,#' '
        CALL WRITE_TEXT
        MOV A,#'1'
        CALL WRITE_TEXT
        MOV A,#'7'
        CALL WRITE_TEXT
        MOV A,#'6'
        CALL WRITE_TEXT
        
        JNB TI,$
        CLR TI
        MOV A,#8
        ADD A,R2
        MOV R2,A
        MOV SBUF,R2         ;Controller Number
        
        MOV A,#' '
        CALL WRITE_TEXT
        
        MOV A,R2
        MOV B,#100          ;A=CENTENAS
        DIV AB
        ADD A,#48
        CALL WRITE_TEXT
        MOV A,B
        MOV B,#10
        DIV AB              ;A=DEZENAS B=UNIDADES
        ADD A,#48
        CALL WRITE_TEXT
        MOV A,B
        ADD A,#48
        CALL WRITE_TEXT
        

        JNB TI,$
        CLR TI
        MOV SBUF,TS          ;Controller Value
        
        MOV A,#' '
        CALL WRITE_TEXT
        MOV A,TS
        MOV B,#100           ;A=CENTENAS
        DIV AB
        ADD A,#48
        CALL WRITE_TEXT
        MOV A,B
        MOV B,#10
        DIV AB               ;A=DEZENAS B=UNIDADES
        ADD A,#48
        CALL WRITE_TEXT
        MOV A,B
        ADD A,#48
        CALL WRITE_TEXT
        
        MOV A,#' '
        CALL WRITE_TEXT
        
        MOV A,TS
        SWAP A
        ANL A,#00001111B
        CALL WRITE_TEXT
        
        RET
        
        




;------------------------------
Delay:  DJNZ TL,$
        MOV TL,#255
        DJNZ TH,Delay
        ;MOV TH,#255
        ;DJNZ TS,DELAY
        RET

LDelay: DJNZ TL,$
        MOV TL,#255
        DJNZ TH,LDelay
        MOV TH,#255
        DJNZ TS,LDELAY
        RET


;----- LCD ---------------

LCD_WRITE_STRING: ;DO MOV DPTR,#STRING BEFORE
        CLR A
        MOVC A,@A+DPTR
        CJNE A,#250,LWSWRT
        RET        
LWSWRT: CALL WRITE_TEXT
        INC DPTR
        JMP LCD_WRITE_STRING
        RET

READ_2_NIBBLES:
        ORL   DATAP,#0F0h   ;Be sure to release datalines (set outputlatches to 1) so we can read the LCD
        SETB  EN
        MOV   A,DATAP       ;Read first part of the return value (high nibble)
        CLR   EN
        ANL   A,#0F0h       ;Only high nibble is usable
        PUSH  ACC
        SETB  EN
        MOV   A,DATAP       ;Read second part of the return value (low nibble)
        CLR   EN 
        ANL   A,#0F0h       ;Only high nibble is usable
        SWAP  A             ;Last received is actually low nibble, so put it in place
        MOV   R7,A 
        POP   ACC 
        ORL   A,R7          ;And combine it with low nibble
        RET


WRITE_2_NIBBLES:
        PUSH  ACC           ;Save A for low nibble
        ORL   DATAP,#0F0h   ;Bits 4..7 <- 1
        ORL   A,#0Fh        ;Dont affect bits 0-3
        ANL   DATAP,A       ;High nibble to display
        SETB  EN 
        CLR   EN 
        POP   ACC           ;Prepare to send
        SWAP  A             ;...second nibble
        ORL   DATAP,#0F0h   ; Bits 4...7 <- 1
        ORL   A,#0Fh        ; Dont affect bits 0...3
        ANL   DATAP,A       ;Low nibble to display
        SETB  EN 
        CLR   EN 
        RET


WAIT_LCD:
        CLR   RS            ;Its a command
        SETB  RW            ;Its a read command
        LCALL READ_2_NIBBLES;Take two nibbles from LCD in A
        JB    ACC.7,WAIT_LCD;If bit 7 high, LCD still busy
        CLR   RW            ;Turn off RW for future commands
        RET


INIT_LCD:
        CLR   RS
        CLR   RW
        CLR   EN
        SETB  EN
        MOV   DATAP,#28h
        CLR   EN
        LCALL WAIT_LCD
        MOV   A,#28h
        LCALL WRITE_2_NIBBLES
        LCALL WAIT_LCD
        MOV   A,#0Ch        ;Aceso sem cursor
        LCALL WRITE_2_NIBBLES
        LCALL WAIT_LCD
        MOV   A,#06h
        LCALL WRITE_2_NIBBLES
        LCALL WAIT_LCD
        RET


CLEAR_LCD:
        CLR   RS
        MOV   A,#01h
        LCALL WRITE_2_NIBBLES;Write A as two separate nibbles to LCD
        LCALL WAIT_LCD
        RET


WRITE_TEXT:
        SETB  RS
        LCALL WRITE_2_NIBBLES
        LCALL WAIT_LCD
        RET



Presentation:
        CALL CLEAR_LCD
        
        ;Chicontroller blasted in
        MOV DPTR,#FCHICONTROLLER
        CALL LCD_WRITE_STRING

        MOV   A,#0C0h       ;SECOND LINE
        LCALL WRITE_2_NIBBLES
        LCALL WAIT_LCD
        
        MOV DPTR,#FBlastedIn
        CALL LCD_WRITE_STRING

        MOV TS,#30
        CALL LDELAY
        
        ;Bali Hai Garop. Date1
        CALL CLEAR_LCD
        
        MOV DPTR,#FBaliHaiG
        CALL LCD_WRITE_STRING

        MOV   A,#0C0h       ;SECOND LINE
        LCALL WRITE_2_NIBBLES
        LCALL WAIT_LCD
        
        MOV DPTR,#FDate1
        CALL LCD_WRITE_STRING

        MOV TS,#30
        CALL LDELAY
        
        
        ;Bali Hai Garop. Date2
        CALL CLEAR_LCD
        
        MOV DPTR,#FBaliHaiG
        CALL LCD_WRITE_STRING

        MOV   A,#0C0h       ;SECOND LINE
        LCALL WRITE_2_NIBBLES
        LCALL WAIT_LCD
        
        MOV DPTR,#FDate2
        CALL LCD_WRITE_STRING

        MOV TS,#30
        CALL LDELAY

        
        ;Bali Hai Garop. Date3
        CALL CLEAR_LCD
        
        MOV DPTR,#FBaliHaiG
        CALL LCD_WRITE_STRING

        MOV   A,#0C0h       ;SECOND LINE
        LCALL WRITE_2_NIBBLES
        LCALL WAIT_LCD
        
        MOV DPTR,#FDate3
        CALL LCD_WRITE_STRING

        MOV TS,#30
        CALL LDELAY
        
        
        ;And here today now
        CALL CLEAR_LCD
        
        MOV DPTR,#FAndHereToday
        CALL LCD_WRITE_STRING

        MOV   A,#0C0h       ;SECOND LINE
        LCALL WRITE_2_NIBBLES
        LCALL WAIT_LCD
        
        MOV DPTR,#FNow
        CALL LCD_WRITE_STRING

        MOV TS,#30
        CALL LDELAY
        RET




;---- LCD TEXT ----
;        Char count 1234567890123456
FINITIALIZING:  DB "INITIALIZING",250
FPLEASEWAIT:    DB "PLEASE WAIT",250
FFIRMWAREVer:   DB "Firmware V1.4",250
FMIDI:          DB "MIDI ",0,1,2,3,4,5,6,7,250
FCHICONTROLLER: DB "CHICONTROLLER",250

CUSTCHARS:      DB   0,  0,  0,  0,   0,  0,  0,  0
                DB   0,  0,  0,  0,   0,  0,255,  0
                DB   0,  0,  0,  0,   0,255,255,  0
                DB   0,  0,  0,  0, 255,255,255,  0
                DB   0,  0,  0,255, 255,255,255,  0
                DB   0,  0,255,255, 255,255,255,  0
                DB   0,255,255,255, 255,255,255,  0
                DB 255,255,255,255, 255,255,255,  0, 250


FBlastedIn: DB "blasted in:",250
FBaliHaiG:  DB "Bali Hai Garop.",250
FDate1:     DB "08/09/2007",250
FDate2:     DB "13/10/2007",250
FDate3:     DB "03/11/2007",250


FAndHereToday:  DB "And here TODAY!",250
FNow:           DB "NOW!!!",250


END




May I ask some other questions?

I didnt need to search or like to learn how to convert 8 bit values to decimal, to show in a LCD for example, but, cant figure out how to do this for 16 bit values.

I have in mind to create menus in the LCD, to configure my midi controller, cant figure out nothing by now, can you give me some analogy how can I create a menu?

How can I make a CASE like in Pascal in ASM, I was thinking, i would need many CJNE for 1,2,3,4.... If I could make using a jump, LIKE this:

JMP A+PC
JMP TRX		; Routine for A=1
JMP TRY		; Routine for A=2
JMP TRZ		; Routine for A=3
JMP ...		; ...


I dont know to program in C , I tried to find some tutorial or else, but nothing significant, where can I find a tutorial to learn how to program C to 8051?


Thanks.

List of 65 messages in thread
TopicAuthorDate
Cant solve, trouble midi controller with adc0804            01/01/70 00:00      
   Some suggestions            01/01/70 00:00      
      Average read            01/01/70 00:00      
   Breadboard ?            01/01/70 00:00      
   Getting rid of the flutter            01/01/70 00:00      
      Averaging            01/01/70 00:00      
         Trying to understand            01/01/70 00:00      
            |Caps            01/01/70 00:00      
            Re: Trying to understand            01/01/70 00:00      
            everything there applies and is exasperated ...            01/01/70 00:00      
               words!            01/01/70 00:00      
                  thanx            01/01/70 00:00      
      Tried your method            01/01/70 00:00      
         Re: Tried your method            01/01/70 00:00      
            Your method            01/01/70 00:00      
               Relocatable assembler ?            01/01/70 00:00      
                  re: Relocatable assembler            01/01/70 00:00      
                     Relocatable assembler            01/01/70 00:00      
                        Examples            01/01/70 00:00      
                           essentially, yes            01/01/70 00:00      
                        You mean...            01/01/70 00:00      
                           Yip            01/01/70 00:00      
                              Am I doing wrong?            01/01/70 00:00      
                                 ds            01/01/70 00:00      
      changed the code, but cant debug!            01/01/70 00:00      
         Re: changed the code, but cant debug!            01/01/70 00:00      
            Certainly it isnt READ            01/01/70 00:00      
               RE: Certainly it isnt READ            01/01/70 00:00      
                  Here goes the code. Thanks for all help            01/01/70 00:00      
                     Pascal            01/01/70 00:00      
   does 'everything' include reading ...            01/01/70 00:00      
   Example?            01/01/70 00:00      
      Simple!            01/01/70 00:00      
         That is all??            01/01/70 00:00      
            Discard LSB for MIDI            01/01/70 00:00      
               He is using Pots            01/01/70 00:00      
                  Vref needs to be solid            01/01/70 00:00      
                     not necessafrily            01/01/70 00:00      
                        OK it's good half the time            01/01/70 00:00      
            Averaging, "dead zone"            01/01/70 00:00      
               No disagree...            01/01/70 00:00      
   Discarding the lsb!            01/01/70 00:00      
      What is Vref            01/01/70 00:00      
         Vref            01/01/70 00:00      
      MIDI power source            01/01/70 00:00      
         Re: MIDI power source, provides power.            01/01/70 00:00      
            re: MIDI power source, provides power.            01/01/70 00:00      
               re: MIDI power source            01/01/70 00:00      
                  Stealing MIDI power            01/01/70 00:00      
                  +5V power on the MIDI connector            01/01/70 00:00      
   Pot matrix? Is possible?            01/01/70 00:00      
      No!            01/01/70 00:00      
         How could I do?            01/01/70 00:00      
            One 4051 for each group of 4 trimmers...            01/01/70 00:00      
      History Lesson            01/01/70 00:00      
         ->Grant            01/01/70 00:00      
   LCD Upgrade            01/01/70 00:00      
      Pull Ups            01/01/70 00:00      
         Thanks Neil, 10k works 100%            01/01/70 00:00      
   How to control CS EN lines...            01/01/70 00:00      
      Google            01/01/70 00:00      
         YEAH!!!            01/01/70 00:00      
            Watch the output polarity            01/01/70 00:00      
      74HCT237            01/01/70 00:00      
   Quality            01/01/70 00:00      

Back to Subject List