Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

help with programming BS2

Status
Not open for further replies.

geraldd

New Member
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?


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

  • NEC8255.pdf
    367 KB · Views: 105
  • Photo0265.jpg
    Photo0265.jpg
    1.1 MB · Views: 152
Last edited:

geraldd

New Member
=/
do you have any recommendations?
i need to use a keypad to output to the LCD, then wireless transmit the info enter from the keypad to another board
 

Nigel Goodwin

Super Moderator
Most Helpful Member
Why not use a second BS2?, or any PIC - all the antique PIO chips are intended for micro-processors not micro-controllers. The 6522 (the 6502 PIO) was a vastly superior chip to the 8255 though.

Or why not use a simple logic IC?, there are various schemes use a couple of pins to feed a TTL or CMOS chip and feeding an LCD.
 

ericgibbs

Well-Known Member
Most Helpful Member
hi,
Also if its a 'pin' shortage problem, why use 8 pins for the LCD data, send the data as two 4 bit nibbles, that will free up 4 PIC pins.
 

geraldd

New Member
im not sure. ): im already this far in the 8255, i guess i have to carry on.

Why not use a second BS2?, or any PIC - all the antique PIO chips are intended for micro-processors not micro-controllers. The 6522 (the 6502 PIO) was a vastly superior chip to the 8255 though.

Or why not use a simple logic IC?, there are various schemes use a couple of pins to feed a TTL or CMOS chip and feeding an LCD.


ohh. i could do that? can show show abit ? how to do it?
hi,
Also if its a 'pin' shortage problem, why use 8 pins for the LCD data, send the data as two 4 bit nibbles, that will free up 4 PIC pins.
 

geraldd

New Member
this is my diagram
8794-Photo0371.jpg
 

ericgibbs

Well-Known Member
Most Helpful Member
im not sure. ):
ohh. i could do that? can show show abit ? how to do it?

hi,
Look at Nigel's tutorials for the PIC, the link to his site is just below my signature on this post, there are examples for driving the LCD with hi/lo 4 bit nibbles.

You can get a 82C55 [cmos version] of the PIO.
 

Pommie

Well-Known Member
Most Helpful Member
You're using 15 pins with an 8255. I normally interface an LCD and a 4x4 keypad using just 11 pins.

4 data pins to LCD and keypad columns via blocking diodes.
4 to keypad rows.
plus RS, R/W and EN to LCD.

You are actually using more pins with the 8255 than you would without it. Plus without the 8255 your code would be much simpler.

Mike.
 

geraldd

New Member
You're using 15 pins with an 8255. I normally interface an LCD and a 4x4 keypad using just 11 pins.

4 data pins to LCD and keypad columns via blocking diodes.
4 to keypad rows.
plus RS, R/W and EN to LCD.

You are actually using more pins with the 8255 than you would without it. Plus without the 8255 your code would be much simpler.

Mike.

do you have a sample code for me to refer to ?
 

Pommie

Well-Known Member
Most Helpful Member
I'm afraid I never use the BS chips. However, if you have the ability to interface an 8255 then interfacing the LCD should be a doddle. The only non obvious bit is reading the keypad. The way you do that is by pulling one of the LCD data lines low and reading the 4 row pins and then repeat for the other columns. The 4 blocking diodes in the column lines are so the LCD still works if all keys on the keypad get pressed at once.

If you don't like the idea of using the same pins for the LCD data lines and the keypad columns then use an additional 4 pins and you will still only be using 15.

Mike.
 

blueroomelectronics

Well-Known Member
You've used 14 I/O lines to connect to the 8255

You could drop the 8255 and connect the LCD & 4x4 keypad to only 10 I/O lines

4 to LCD D4..D7 and the keypad rows
4 to keypad columns
1 RS
1 E
GND RW
 

geraldd

New Member
I'm afraid I never use the BS chips. However, if you have the ability to interface an 8255 then interfacing the LCD should be a doddle. The only non obvious bit is reading the keypad. The way you do that is by pulling one of the LCD data lines low and reading the 4 row pins and then repeat for the other columns. The 4 blocking diodes in the column lines are so the LCD still works if all keys on the keypad get pressed at once.

If you don't like the idea of using the same pins for the LCD data lines and the keypad columns then use an additional 4 pins and you will still only be using 15.

Mike.

You've used 14 I/O lines to connect to the 8255

You could drop the 8255 and connect the LCD & 4x4 keypad to only 10 I/O lines

4 to LCD D4..D7 and the keypad rows
4 to keypad columns
1 RS
1 E
GND RW

sorry im pretty weak at programming so im not very sure on how u guys do that =/
does any one have a sample ?
 

Pommie

Well-Known Member
Most Helpful Member
If you wrote the code to interface to an 8255 then you should have no problem interfacing to an LCD and keypad. If you found the code on the internet then stay with it, as you won't get any help from me.

Mike.
 

BrownOut

Banned
I can't find a problem with your initialization, but I just briefly looked over it. If you've double/triple checked everything, it's time to hook up a logic analyzer and verify the connecting signals are correct. You're school should have one. If not, you might try a dual-trace scope to observe critical signals, or make a simple logic analyzer using LED's and single step your program. I can't remember if BS allows single stepping, but you can program it and use your keypad as a step commander.
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top