Koda: |
copyright = MCS Electronics www = http://www.mcselec.com email = avr@mcselec.com comment = Optimized LCD library libversion = 1.00 date = 2 februari 2001 statement = No SOURCE code from the library may be distributed in any form statement = Of course this does not applie for the COMPILED code when you have a BASCOM-AVR license history = No known bugs. ;the default library for BASCOM can handle worst case scenarios where each pin of the LCD ;is connected to a random pin of the micro ;When we choose the data port pin in sequence, we can save some code ;This lib shows how to use the LCD in 4 bit mode with 2 E lines ! ;Rs = PortB.0 ;RW = PortB.1 we dont use the R/W option of the LCD in this version so connect to ground ; E = PortB.2 ;E2 = PortB.3 for lcd with 2 chips ;Db4 = PortB.4 the data bits must be in a nibble to save code ;Db5 = PortB.5 ;Db6 = PortB.6 ;Db7 = PortB.7 ;This routine is called when the LCD must be initialized ;dont forget to dimension a byte named ___LCDE [_Init_LCD] .EQU LCDDDR=$17 ; change to another address for DDRD ($11) .EQU LCDPORT=$18 ; change to another address for PORTD ($12) _Init_LCD: *BASIC: waitms 10 Ldi R24, &B11111111 ; all outputs Out LCDDDR,R24 ; write to Data direction Ldi R24, &B00110000 ; set logic level Out LCDPORT,R24 ; write to output pins Ldi r16,3 ; repeat 3 times _Init_LCD1: SBi LCDPORT, 2 ; E high Cbi LCDPORT, 2 ; E low Sbi LCDPORT, 3 ; E2 high Cbi LCDPORT, 3 ; E2 low *BASIC: waitms 1 Dec R16 Brne _Init_LCD1 ; until we are ready Cbi LCDPORT, 4 ; DB4 must be set low now SBi LCDPORT, 2 ; E high Cbi LCDPORT, 2 ; E low Sbi LCDPORT,3 ; E2 high Cbi LCDPORT,3 ; E2 low *BASIC: waitms 1 Ldi R24,0 * Sts {___LCDE},R24 ; we use E1 now Ldi R24, 40 ; 4 bit mode rcall _Lcd_control Ldi _temp1,14 ; Display on, Cursor on, Noblink rcall _Lcd_control Ldi _temp1,6 ; Cursor moves right, text doesn't move rcall _Lcd_control Ldi R24,255 * Sts {___LCDE},R24 ; we use E2 now Ldi R24, 40 ; 4 bit mode rcall _Lcd_control Ldi _temp1,14 ; Display on, Cursor on, Noblink rcall _Lcd_control Ldi _temp1,6 ; Cursor moves right, text doesn't move Rjmp _Lcd_control [END] ;high nibble must be written first ;rw must be low for a write ;rs must be low for control, high for data ;data passed in r24 [_Write_lcd] _Write_lcd: Set ; RS flag must be made 1 Rjmp _Write_lcd_Byte _Lcd_control: Clt ; RS flag must be 0 _Write_lcd_Byte: Mov r25,r24 ; save data Rcall _Write_lcd_Nibble ; write lower nibble Mov R24,r25 ; get data back Swap R24 ; swap nibble _Write_lcd_nibble: * Lds R2,{___LCDE} Tst R2 Brne _Write_lcd_nibble2 ; if E2 selected Bld R24,0 ; RS flag Sbr R24,4 ; E high Cbr R24,10 ; E2 and RW low Out LCDPORT, R24 ; write Cbi LCDPORT,2 ; disable Rjmp _Write_lcd_nibble3 _Write_lcd_nibble2: Bld R24,0 ; RS flag Sbr R24,8 ; E high Cbr R24,6 ; E1 and RW low Out LCDPORT, R24 ; write Cbi LCDPORT,3 ; disable _Write_lcd_nibble3: @genus(100) ; wait for 100 uS Ret [END] [_CLS] $EXTERNAL _WRITE_LCD _Cls: Ldi R24,1 ; Clear display Rcall _Lcd_control *BASIC: waitms 3 Ldi R24,128 ; Select line 1 Rjmp _Lcd_control ; finish [END] |
Koda: |
Config Lcdpin = Pin , Db7 = PortB.7 , Db6 = PortB.6 , Db5 = PortB.5 , Db4 = PortB.4 , E = PortB.3 , Rs = PortB.2 |
Koda: |
;Rs = PortB.1
;RW = PortB.0 we dont use the R/W option of the LCD in this version so connect to ground ; E = PortB.2 ;E2 = PortB.3 for lcd with 2 chips ;Db4 = PortB.4 the data bits must be in a nibble to save code ;Db5 = PortB.5 ;Db6 = PortB.6 ;Db7 = PortB.7 |
mato1111 je napisal/a: | ||
Jazbi probal tako (sem samo zamenjal pina Rs in RW):
|
Koda: |
When you want to have less code you need fixed pins for the LCD display.
With the statement $LIB "LCD4E2.LBX" you specify that the LCD4.LIB will be used. The following connections are used in the asm code: Rs = PortB.0 RW = PortB.1 we don’t use the R/W option of the LCD in this version so connect to ground E = PortB.2 E2 = PortB.3 the second E pin of the LCD Db4 = PortB.4 the data bits must be in a nibble to save code Db5 = PortB.5 Db6 = PortB.6 Db7 = PortB.7 You can change the lines from the lcd4e2.lib file to use another port. Just change the address used : .EQU LCDDDR=$17 ; change to another address for DDRD ($11) .EQU LCDPORT=$18 ; change to another address for PORTD ($12) |
stursc je napisal/a: | ||
Napiši svoj config
Primer:
Lp, sturs |
Koda: |
copyright = MCS Electronics www = http://www.mcselec.com email = avr@mcselec.com comment = Optimized LCD library libversion = 1.00 date = 2 februari 2001 statement = No SOURCE code from the library may be distributed in any form statement = Of course this does not applie for the COMPILED code when you have a BASCOM-AVR license history = No known bugs. ;the default library for BASCOM can handle worst case scenarios where each pin of the LCD ;is connected to a random pin of the micro ;When we choose the data port pin in sequence, we can save some code ;This lib shows how to use the LCD in 4 bit mode with 2 E lines ! ;Rs = PortB.0 ;RW = PortB.1 we dont use the R/W option of the LCD in this version so connect to ground ; E = PortB.2 ;E2 = PortB.3 for lcd with 2 chips ;Db4 = PortB.4 the data bits must be in a nibble to save code ;Db5 = PortB.5 ;Db6 = PortB.6 ;Db7 = PortB.7 ;This routine is called when the LCD must be initialized ;dont forget to dimension a byte named ___LCDE [_Init_LCD] .EQU LCDDDR=$17 ; change to another address for DDRD ($11) .EQU LCDPORT=$18 ; change to another address for PORTD ($12) _Init_LCD: *BASIC: waitms 10 Ldi R24, &B11111111 ; all outputs Out LCDDDR,R24 ; write to Data direction Ldi R24, &B00110000 ; set logic level Out LCDPORT,R24 ; write to output pins Ldi r16,3 ; repeat 3 times _Init_LCD1: SBi LCDPORT, 2 ; E high Cbi LCDPORT, 2 ; E low Sbi LCDPORT, 3 ; E2 high Cbi LCDPORT, 3 ; E2 low *BASIC: waitms 1 Dec R16 Brne _Init_LCD1 ; until we are ready Cbi LCDPORT, 4 ; DB4 must be set low now SBi LCDPORT, 2 ; E high Cbi LCDPORT, 2 ; E low Sbi LCDPORT,3 ; E2 high Cbi LCDPORT,3 ; E2 low *BASIC: waitms 1 Ldi R24,0 * Sts {___LCDE},R24 ; we use E1 now Ldi R24, 40 ; 4 bit mode rcall _Lcd_control Ldi _temp1,14 ; Display on, Cursor on, Noblink rcall _Lcd_control Ldi _temp1,6 ; Cursor moves right, text doesn't move rcall _Lcd_control Ldi R24,255 * Sts {___LCDE},R24 ; we use E2 now Ldi R24, 40 ; 4 bit mode rcall _Lcd_control Ldi _temp1,14 ; Display on, Cursor on, Noblink rcall _Lcd_control Ldi _temp1,6 ; Cursor moves right, text doesn't move Rjmp _Lcd_control [END] ;high nibble must be written first ;rw must be low for a write ;rs must be low for control, high for data ;data passed in r24 [_Write_lcd] _Write_lcd: Set ; RS flag must be made 1 Rjmp _Write_lcd_Byte _Lcd_control: Clt ; RS flag must be 0 _Write_lcd_Byte: Mov r25,r24 ; save data Rcall _Write_lcd_Nibble ; write lower nibble Mov R24,r25 ; get data back Swap R24 ; swap nibble _Write_lcd_nibble: * Lds R2,{___LCDE} Tst R2 Brne _Write_lcd_nibble2 ; if E2 selected Bld R24,1 ; RS flag, spremenil Jaka <------------- Sbr R24,4 ; E high Cbr R24,10 ; E2 and RW low Out LCDPORT, R24 ; write Cbi LCDPORT,2 ; disable Rjmp _Write_lcd_nibble3 _Write_lcd_nibble2: Bld R24,1 ; RS flag, spremenil Jaka <------------------ Sbr R24,8 ; E high Cbr R24,6 ; E1 and RW low Out LCDPORT, R24 ; write Cbi LCDPORT,3 ; disable _Write_lcd_nibble3: @genus(100) ; wait for 100 uS Ret [END] [_CLS] $EXTERNAL _WRITE_LCD _Cls: Ldi R24,1 ; Clear display Rcall _Lcd_control *BASIC: waitms 3 Ldi R24,128 ; Select line 1 Rjmp _Lcd_control ; finish [END] |
Koda: |
;high nibble must be written first
;rw must be low for a write ;rs must be low for control, high for data ;data passed in r24 [_Write_lcd] _Write_lcd: Set ; RS flag must be made 1 Rjmp _Write_lcd_Byte _Lcd_control: Clt ; RS flag must be 0 _Write_lcd_Byte: Mov r25,r24 ; save data Rcall _Write_lcd_Nibble ; write lower nibble Mov R24,r25 ; get data back Swap R24 ; swap nibble _Write_lcd_nibble: * Lds R2,{___LCDE} Tst R2 Brne _Write_lcd_nibble2 ; if E2 selected Bld R24,1 ; RS flag <---------- Spremenil Jaka Sbr R24,4 ; E high Cbr R24,9 ; E2 and RW low <---------- Spremenil Jaka Out LCDPORT, R24 ; write Cbi LCDPORT,2 ; disable Rjmp _Write_lcd_nibble3 _Write_lcd_nibble2: Bld R24,1 ; RS flag <---------- Spremenil Jaka Sbr R24,8 ; E high Cbr R24,5 ; E1 and RW low <---------- Spremenil Jaka Out LCDPORT, R24 ; write Cbi LCDPORT,3 ; disable _Write_lcd_nibble3: @genus(100) ; wait for 100 uS Ret [END] |