I want to learn to program a LCD and I am doing a tutorial. This project contain two files one written below and the second file is in the website shown in the end of the post.
-Can you guys tell me if the question I wrote in the code is correct or wrong? I got 18 question
;****************************************************************
;* LCD driver routines, with a simple menu *
;* Assembler version: *
;* Filename: *
;* Main.asm (main routine) *
;* Dependents: *
;* LCD.asm *
;* 18F8722.lkr or 18F87J11.lkr *
;* Jan 16 2013 NPS *
;* PIC18 Explorer. The following functions are included *
;* with this code: *
;* 1. Menu Item 1 *
;* Add own code *
;* 2. Menu Item 2 *
;* Add own code *
;* 3. Menu Item 3 *
;* Add own code *
;****************************************************************
;1. This is the configuration bits changed to allow the different microcontroller to be used?
#ifdef __18F8722
list p=18F8722
#include p18F8722.inc
CONFIG OSC = HSPLL
CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG PWRT = OFF
CONFIG BOREN = OFF
CONFIG WDT = OFF
CONFIG MCLRE = ON
CONFIG LVP = OFF
CONFIG XINST = OFF
#endif
#ifdef __18F87J11
list p=18F87J11
#include p18F87J11.inc
CONFIG FOSC = HSPLL
CONFIG STVREN = OFF,XINST = OFF,WDTEN = OFF,CP0 = OFF,FCMEN = OFF,IESO = OFF
CONFIG MODE = MM
#endif
;2. -This make the porta,5 equal to scroll? -When ever you use scroll this is like you use porta,5?
#define scroll_dir TRISA,5
#define scroll PORTA,5 ;Push-button RA5 on PCB
#define select_dir TRISB,0
#define select PORTB,0 ;Push-button RB0 on PCB
;3.Dont understand what they doing with theEEPROM memory?
#define EEPROM_CS LATA,3 ; EEprom chip select
#define EEPROM_CS_TRIS TRISA,3 ; EEprom chip select
4.what is these 2 line code doing?
EXTERN LCDInit, temp_wr, d_write, i_write, LCDLine_1, LCDLine_2
EXTERN Delay,Check,InitSPI
;5. They giving location for the SFR into the memory location?- but what is the variable UDATE_ACS?
variables UDATA_ACS
ptr_pos RES 1
ptr_count RES 1
temp_1 RES 1
temp_2 RES 1
temp_3 RES 1
;6 I dont understand why they use the NOP instruction here? -we dont need some delay here?
STARTUP CODE 0
NOP
goto start
NOP
NOP
NOP
PROG1 CODE ;6 what is this CODE variable doing?
;7. is this the table to store the character we want to put?
stan_table ;table for standard code
; "XXXXXXXXXXXXXXXX"
; ptr:
data " Menu Item 1 " ;0
data " " ;16
data " Menu Item 2 " ;32
data " Menu Item 3 " ;48
data "RB0=Now RA5=Next" ;64
data "Microchip PICDEM" ;80
data " PIC18 Explorer " ;96
data "LCDMenu Demo NPS" ;112
data "Item 3 Execution" ;128
data "Item 2 Execution" ;144
data "Item 1 Execution" ;160
start
bsf OSCTUNE,PLLEN ;8. what is Osctune doing? Enable PLL
call LCDInit ;Initialize the LCD
;9i the LCinit just call an instruction in the other file, but what happen in the other file?
#ifdef __18F8722
movlw b'00001110' ;RA0 = analog input
movwf ADCON1
#endif
#ifdef __18F87J11
bsf WDTCON,ADSHR ;Shared SFR
setf ANCON0 ;10. this set the whole bits of ANCON0 or a single bit?
setf ANCON1
bcf ANCON1,0 ;11. having a zero in the bi one of ANCON1 Make RA0 Analog input?
bcf WDTCON,ADSHR
#endif
12. what is WDTCON, TXSTA and RCSTA?
movlw B'10100100' ;initialize USART
movwf TXSTA ;8-bit, Async, High Speed
movlw .255
movwf SPBRG ;9.6kbaud @ 40MHz
movlw B'10010000'
movwf RCSTA
bsf TRISB,0 ;make switch RB0 an Input
bsf TRISA,5 ;make switch RA5 an Input
;**************** STANDARD CODE MENU SELECTION *******************
;Introduction
movlw .80 ;send "Microchip PICDEM" to LCD
movwf ptr_pos
call stan_char_1
movlw .96 ;send " PIC18 Explorer " to LCD
movwf ptr_pos
call stan_char_2
call delay_1s ;delay for display
movlw .112 ;send "LCDMenu Demo " to LCD
movwf ptr_pos
call stan_char_1
call delay_1s ;delay for display
call delay_1s ;delay for display
menu
;13. what is the purpose of waiting for A5 and RBo to release?
btfss scroll ;wait for RA5 release
goto $-2
btfss select ;wait for RB0 release
goto $-2
;------------------ MENU item 1 ----------------------------
call delay_100ms
call delay_100ms
call delay_100ms
btfss scroll ;YES
bra $-2 ;wait for release
;14 why there is a scroll button here? in the hardwre there is only once they ask when you press it goes to the next one.
;-When you press the button it goes low, when you dont press it is high?
;-this btfss is just to test if the button is not touched anymore,
movlw 0x00 ;Display " Menu Item 1 "
movwf ptr_pos
call stan_char_1
;15 when you move a number in dot for example into w register from literal, then move to ptr_pos, the ptr_pos shows the data wrtten ino .64 from the table?
;16 what does the stan char_2 does?-the stan char_2 represent the second line? and what the stan_char_1 does?it represent the first line in the LDR?
movlw .64 ;Display "RB0=Now RA5=Next"
movwf ptr_pos
call stan_char_2
;wait for key press
v_wait
btfss select ;execute item1?
bra item1 ;YES
btfsc scroll ;Goto Next
bra v_wait ;NO
;16 when you press the key, the scroll goes low and excetute the next instruction which is bra v_wait. For scroll, when you press the button scroll, scroll button goes low and skip the next uinstrution as it is now btfsc instead of btfss. this statement is correct?
;------------------ MENU item 2 ----------------------------
menu_2
call delay_100ms
call delay_100ms
call delay_100ms
btfss scroll ;wait for RA5 release
bra $-2
movlw .32 ;Display "Menu Item 2"
movwf ptr_pos
call stan_char_1
movlw .64 ;Display "RB0=Now RA5=Next"
movwf ptr_pos
call stan_char_2
;wait for key press
t_wait
btfss select ;Execute Item 2 code?
bra item2 ;YES
btfsc scroll ;Goto Next
bra t_wait ;NO
;------------------ MENU item 3 ----------------------------
menu_3
call delay_100ms
call delay_100ms
call delay_100ms
btfss select; ;wait for RB0 release
bra $-2;
movlw .48 ;Display "Menu Item 3 "
movwf ptr_pos
call stan_char_1
movlw .64 ;Display "RB0=Now RA5=Next"
movwf ptr_pos
call stan_char_2
c_wait
btfss select ;execute item3 code?
bra item3 ;YES
btfsc scroll ;Go back to Main menu
bra c_wait ;NO
bra menu ;begining of menu
;*******************************************************************
;************* USER CODE *************************************
;------------- Menu Item 1 -------------------------------------
item1
movlw .160 ;Display "Item 1 Execution"
movwf ptr_pos
call stan_char_2
bra menu
;------------- Menu Item 2 -------------------------------------
item2
movlw .144 ;Display "Item 2 Execution"
movwf ptr_pos
call stan_char_2
bra menu_2
;------------- Menu Item 3 -------------------------------------
item3
movlw .128 ;Display "Item 3 Execution"
movwf ptr_pos
call stan_char_2
bra menu_3
; bra menu ; go back to menu
;************************** ROUTINES ******************************
;******************************************************************
;******************************************************************
;17. how this code of stan_char_1 work?
;----Standard code, Place characters on line-1--------------------------
stan_char_1
call LCDLine_1 ;mvoe cursor to line 1
movlw .16 ;1-full line of LCD
movwf ptr_count
movlw UPPER stan_table
movwf TBLPTRU
movlw HIGH stan_table
movwf TBLPTRH
movlw LOW stan_table
movwf TBLPTRL
movf ptr_pos,W
addwf TBLPTRL,F
clrf WREG
addwfc TBLPTRH,F
addwfc TBLPTRU,F
stan_next_char_1
tblrd *+
movff TABLAT,temp_wr
call d_write ;send character to LCD
decfsz ptr_count,F ;move pointer to next char
bra stan_next_char_1
movlw "\n" ;move data into TXREG
movwf TXREG ;next line
btfss TXSTA,TRMT ;wait for data TX
goto $-2
movlw "\r" ;move data into TXREG
movwf TXREG ;carriage return
btfss TXSTA,TRMT ;wait for data TX
goto $-2
return
;----Standard code, Place characters on line-2--------------------------
stan_char_2
call LCDLine_2 ;move cursor to line 2
movlw .16 ;1-full line of LCD
movwf ptr_count
movlw UPPER stan_table
movwf TBLPTRU
movlw HIGH stan_table
movwf TBLPTRH
movlw LOW stan_table
movwf TBLPTRL
movf ptr_pos,W
addwf TBLPTRL,F
clrf WREG
addwfc TBLPTRH,F
addwfc TBLPTRU,F
stan_next_char_2
tblrd *+
movff TABLAT,temp_wr
call d_write ;send character to LCD
decfsz ptr_count,F ;move pointer to next char
bra stan_next_char_2
movlw "\n" ;move data into TXREG
movwf TXREG ;next line
btfss TXSTA,TRMT ;wait for data TX
goto $-2
movlw "\r" ;move data into TXREG
movwf TXREG ;carriage return
btfss TXSTA,TRMT ;wait for data TX
goto $-2
return
;----------------------------------------------------------------------
;------------------ 100ms Delay --------------------------------
;18 -is the rest of the following line are delays codes? -why there are so many delay labels and code,? because we are only using delay 100ms
delay_100ms
call Delaysmall
call Delaysmall
call Delaysmall
call Delaysmall
call Delaysmall
call Delaysmall
call Delaysmall
call Delaysmall
call Delaysmall
call Delaysmall
return
Delaysmall ;100ms at 4Mhz
movlw 0xFF
movwf temp_1
movlw 0x83
movwf temp_2
d100l1
decfsz temp_1,F
bra d100l1
decfsz temp_2,F
bra d100l1
return
;---------------- 1s Delay -----------------------------------
delay_1s
call Ldelay
call Ldelay
call Ldelay
call Ldelay
call Ldelay
call Ldelay
call Ldelay
call Ldelay
call Ldelay
call Ldelay
return
Ldelay ;1S at f Mhx
movlw 0xFF
movwf temp_1
movwf temp_2
movlw 0x05
movwf temp_3
d1l1
decfsz temp_1,F
bra d1l1
decfsz temp_2,F
bra d1l1
decfsz temp_3,F
bra d1l1
return
;*********************************************************************
end
The code for the LCD file is here.
https://www.eevblog.com/forum/microcontrollers/how-can-you-understand-a-code-s/?topicseen