Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program other
- ' Declarations section
- dim Data_Pin as sbit at RA0_bit
- dim Clk_Pin as sbit at RA1_bit
- dim Enable_Pin as sbit at RA2_bit
- 'Always mention this definition statement
- dim Low_Nibble, High_Nibble, p, q, Mask, N,t, RS, Flag, temp as byte
- dim Message1 as string[20]
- dim Message2 as string[20]
- sub procedure Write_LCD_Nibble(dim N as byte)
- Enable_Pin = 0
- '****** Write RS *********
- Clk_Pin = 0
- Data_Pin = RS
- Clk_Pin = 1
- Clk_Pin = 0
- '// ****** End RS Write
- 'Shift in 4 bits
- Mask = 8
- for t=0 to 4
- Flag = N and Mask
- if Flag =0 then
- Data_Pin = 0
- else
- Data_Pin = 1
- end if
- Clk_Pin = 1
- Clk_Pin = 0
- Mask = Mask >> 1
- next t
- ' // One more clock because SC and ST clks are tied
- Clk_Pin = 1
- Clk_Pin = 0
- Data_Pin = 0
- Enable_Pin = 1
- Enable_Pin = 0
- end sub
- '// ******* Write Nibble Ends
- sub procedure Write_LCD_Data(dim D as byte)
- RS = 1 'It is Data, not command
- Low_Nibble = D and 15
- High_Nibble = D/16
- Write_LCD_Nibble(High_Nibble)
- Write_LCD_Nibble(Low_Nibble)
- end sub
- sub procedure Write_LCD_Cmd(dim C as byte)
- RS = 0 'It is command, not data
- Low_Nibble = C and 15
- High_Nibble = C/16
- Write_LCD_Nibble(High_Nibble)
- Write_LCD_Nibble(Low_Nibble)
- end sub
- sub procedure Initialize_LCD()
- Delay_ms(50)
- Write_LCD_Cmd(0x20) ' Wake-Up Sequence
- Delay_ms(50)
- Write_LCD_Cmd(0x20)
- Delay_ms(50)
- Write_LCD_Cmd(0x20)
- Delay_ms(50)
- Write_LCD_Cmd(0x28) '4-bits, 2 lines, 5x7 font
- Delay_ms(50)
- Write_LCD_Cmd(0x0C) ' Display ON, No cursors
- Delay_ms(50)
- Write_LCD_Cmd(0x06) ' Entry mode- Auto-increment, No Display shifting
- Delay_ms(50)
- Write_LCD_Cmd(0x01)
- Delay_ms(50)
- end sub
- sub procedure Position_LCD(dim x, y as byte)
- temp = 127 + y
- if x = 2 then
- temp = temp + 64
- end if
- Write_LCD_Cmd(temp)
- end sub
- sub procedure Write_LCD_Text( dim ptr as ^byte)
- dim temp as byte
- temp = ptr
- while temp > 0
- Write_LCD_Data(temp)
- inc(temp)
- wend
- end sub
- main:
- Message1 = "3-Wire LCD"
- Message2 = "using 74HC595"
- CMCON = 7 'Disable Comparators
- TRISB = 0 'All Outputs
- TRISA = 0
- PORTB = 0
- Initialize_LCD()
- while (TRUE)
- Position_LCD(1,4)
- Write_LCD_Text(@Message1)
- Position_LCD(2,2)
- Write_LCD_Text(@Message2)
- Delay_ms(1500)
- Write_LCD_Cmd(0x01) ' Clear LCD
- delay_ms(1000)
- wend
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement