hi to all. this is my code for using BS2 a PPI 8255 to control a LCD
as im quite new, im not sure which part of my program went wrong
the attached files are my 8255 datasheet and LCD
can any one tell me whats wrong with my initialization?
as im quite new, im not sure which part of my program went wrong
the attached files are my 8255 datasheet and LCD
can any one tell me whats wrong with my initialization?
Code:
' {$STAMP BS2}
' {$PBASIC 2.5}
' ----- Constants
E_LCD PIN 1
Reset_8255 PIN 2
A1_8255 PIN 3
A0_8255 PIN 4
WR_8255 PIN 5
RD_8255 PIN 6
CS_8255 PIN 7
DB0_8255 PIN 8
DB1_8255 PIN 9
DB2_8255 PIN 10
DB3_8255 PIN 11
DB4_8255 PIN 12
DB5_8255 PIN 13
DB6_8255 PIN 14
DB7_8255 PIN 15
' ----- Initialization
OUTS = $00 ' Set Outputs Low
DIRS = $FF ' Set I/O Direction
GOSUB Init_8255 'Initialize PPI 8255
GOSUB LCD_Init ' Initialize The LCD Display
' ----- Main Code
Main:
LOW A1_8255 'Set address control A1 & A0 Low to set the 8255 Port A for Output
LOW A0_8255
OUTH = %01000001 'Set databus for function set
HIGH RD_8255 'Set Read control high (inactive)
LOW WR_8255 'Set Write control Low (active)
LOW CS_8255 'Set Chip Select Low (Active)
PULSOUT WR_8255, 5 'Pulse Write control Low (Active) for 10 us (port changes state)
HIGH CS_8255 'Set Chip Select High (Inactive) - Disable the 8255 databus
GOSUB writeLCDdata
PAUSE 100
GOTO Main
' ----- Subroutines
Init_8255: 'Initialize 8255 to All Outputs at Active Low state
OUTL = $FF 'Set all the control lines (P0-P7) High (Inactive)
PAUSE 50 'Settling time for a few ms (50 ms)
LOW Reset_8255 '8255 is Reset (Active)
HIGH WR_8255 'Set Write control High (Inactive)
LOW RD_8255 'Set Read control Low (Active)
HIGH A1_8255 'Set Address control A1 & A0 High to access the control word register
HIGH A0_8255
OUTH = $81 'Set databus (P8-P15) to $81 for MODE 0 - Port A & B ports as outputs and C as half half
LOW CS_8255 'Set Chip Select Low (Active)
PULSOUT WR_8255, 50 'Pulse Write control Low (Active) for 100 us (duration not critical)
HIGH CS_8255 'Set Chip Select High (Inactive) - All outputs are set to Active Low
RETURN
LCD_Init: 'Set up 8255 Port A for Output
LOW A1_8255 'Set address control A1 & A0 Low to set the 8255 Port A for Output
LOW A0_8255
OUTH = %00111000 'Set databus for function set
HIGH RD_8255 'Set Read control high (inactive)
LOW WR_8255 'Set Write control Low (active)
LOW CS_8255 'Set Chip Select Low (Active)
PULSOUT WR_8255, 5 'Pulse Write control Low (Active) for 10 us (port changes state)
HIGH CS_8255 'Set Chip Select High (Inactive) - Disable the 8255 databus
GOSUB writeLCDcmd
GOSUB writeLCDcmd
GOSUB writeLCDcmd
LOW A1_8255 'Set address control A1 & A0 Low to set the 8255 Port A for Output
LOW A0_8255
OUTH = %00001000 'Set databus for display off
HIGH RD_8255 'Set Read control high (inactive)
LOW WR_8255 'Set Write control Low (active)
LOW CS_8255 'Set Chip Select Low (Active)
PULSOUT WR_8255, 5 'Pulse Write control Low (Active) for 10 us (port changes state)
HIGH CS_8255 'Set Chip Select High (Inactive) - Disable the 8255 databus
GOSUB writeLCDcmd
LOW A1_8255 'Set address control A1 & A0 Low to set the 8255 Port A for Output
LOW A0_8255
OUTH = %00000001 'Set databus for clear display
HIGH RD_8255 'Set Read control high (inactive)
LOW WR_8255 'Set Write control Low (active)
LOW CS_8255 'Set Chip Select Low (Active)
PULSOUT WR_8255, 5 'Pulse Write control Low (Active) for 10 us (port changes state)
HIGH CS_8255 'Set Chip Select High (Inactive) - Disable the 8255 databus
GOSUB writeLCDcmd
LOW A1_8255 'Set address control A1 & A0 Low to set the 8255 Port A for Output
LOW A0_8255
OUTH = %00000110 'Set databus for entry mode set
HIGH RD_8255 'Set Read control high (inactive)
LOW WR_8255 'Set Write control Low (active)
LOW CS_8255 'Set Chip Select Low (Active)
PULSOUT WR_8255, 5 'Pulse Write control Low (Active) for 10 us (port changes state)
HIGH CS_8255 'Set Chip Select High (Inactive) - Disable the 8255 databus
GOSUB writeLCDcmd
LOW A1_8255 'Set address control A1 & A0 Low to set the 8255 Port A for Output
LOW A0_8255
OUTH = %00001110 'Set databus for turn display and cursor on
HIGH RD_8255 'Set Read control high (inactive)
LOW WR_8255 'Set Write control Low (active)
LOW CS_8255 'Set Chip Select Low (Active)
PULSOUT WR_8255, 5 'Pulse Write control Low (Active) for 10 us (port changes state)
HIGH CS_8255 'Set Chip Select High (Inactive) - Disable the 8255 databus
GOSUB writeLCDcmd
RETURN
writeLCDcmd:
LOW A1_8255 'Set address control A1 & A0 to set the 8255 Port B for Output
HIGH A0_8255 'take note of the reverse from the orignal code
OUTH = %00000000 'Set databus for pattern2
HIGH RD_8255 'Set Read control high (inactive)
LOW WR_8255 'Set Write control Low (active)
LOW CS_8255 'Set Chip Select Low (Active)
PULSOUT WR_8255, 5 'Pulse Write control Low (Active) for 10 us (port changes state)
HIGH CS_8255
PAUSE 50
PULSOUT E_LCD,1
PAUSE 100
OUTH = %01100000 'Set databus for back high
HIGH RD_8255 'Set Read control high (inactive)
LOW WR_8255 'Set Write control Low (active)
LOW CS_8255 'Set Chip Select Low (Active)
PULSOUT WR_8255, 5 'Pulse Write control Low (Active) for 10 us (port changes state)
HIGH CS_8255
RETURN
writeLCDdata:
LOW A1_8255 'Set address control A1 & A0 to set the 8255 Port B for Output
HIGH A0_8255 'take note of the reverse from the orignal code
OUTH = %00100000 'Set databus for informatio displayed to LCD
HIGH RD_8255 'Set Read control high (inactive)
LOW WR_8255 'Set Write control Low (active)
LOW CS_8255 'Set Chip Select Low (Active)
PULSOUT WR_8255, 5 'Pulse Write control Low (Active) for 10 us (port changes state)
HIGH CS_8255
PAUSE 50
PULSOUT E_LCD,1
PAUSE 100
OUTH = %01100000 'Set databus for back high
HIGH RD_8255 'Set Read control high (inactive)
LOW WR_8255 'Set Write control Low (active)
LOW CS_8255 'Set Chip Select Low (Active)
PULSOUT WR_8255, 5 'Pulse Write control Low (Active) for 10 us (port changes state)
HIGH CS_8255
RETURN
Attachments
Last edited: