I have been enjoying the fun of programming again using the GreatCowBasic and my recent purchase of a PICKit 2 express. I though I could share a little number counter program. No claims to correct use of code nor style. The bottom line is this is working code. The PortD was used for debugging and could be removed. MC14498B has no timing problems but turn the LED/MC14489 on first and then start the programmer/16f887 proto bd. Have fun!
'LED display with MC14489B chip
' Three pin driver demo
'12/7/2007 Mike Otte
'Pin Direction
dir EnPin out
Set EnPin On
DIR PORTD.0 OUT
Set PORTD.0 OFF
dir DataPin out
set DataPin off
dir ClkPin out
set ClkPin off
'DIR PORTD.1 OUT
'DIR PORTD.2 OUT
Mainloop:
'send config command E1= hex decode,normal mode with 4 digits
set Datapin off
Set EnPin OFF
Wait 5 ms
ShiftOut(0xE0) ' Resets display
Set EnPin On
set Datapin off
Set EnPin OFF
Wait 5 ms
ShiftOut(0xE1) ' F1 = 3dig F9 = 2digits
Set EnPin On
For num = 0 to 255
hundreds=num/100
temp=num-100*hundreds
tens=temp/10
ones=temp-tens*10
tens = tens AND 0x0f
rotate tens left simple
rotate tens left simple
rotate tens left simple
rotate tens left simple
temp = tens + ones
set Datapin off
Set PORTD.0 OFF
Set EnPin OFF
Wait 5 ms
ShiftOut(0XFF)
ShiftOut(hundreds)
ShiftOut(temp)
Set EnPin On
Set PORTD.0 ON
Wait 10 10ms
next
it would help to know what you are talking spi to. This routine only sent to the display. No receive as it is. To send 9bit spi you would splice the code on the front or back of the 8 bits. Is the 9 bit for master/slaves like 485?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have been enjoying the fun of programming again using the GreatCowBasic and my recent purchase of a PICKit 2 express. I though I could share a little number counter program. No claims to correct use of code nor style. The bottom line is this is working code. The PortD was used for debugging and could be removed. MC14498B has no timing problems but turn the LED/MC14489 on first and then start the programmer/16f887 proto bd. Have fun!
'LED display with MC14489B chip
' Three pin driver demo
'12/7/2007 Mike Otte
#chip 16F887, 20
#config INTOSC
' Shift Variables
#define ClkPin PORTB.2
#define DataPin PORTB.1
#define EnPin PORTB.3
'Pin Direction
dir EnPin out
Set EnPin On
DIR PORTD.0 OUT
Set PORTD.0 OFF
dir DataPin out
set DataPin off
dir ClkPin out
set ClkPin off
'DIR PORTD.1 OUT
'DIR PORTD.2 OUT
Mainloop:
'send config command E1= hex decode,normal mode with 4 digits
set Datapin off
Set EnPin OFF
Wait 5 ms
ShiftOut(0xE0) ' Resets display
Set EnPin On
set Datapin off
Set EnPin OFF
Wait 5 ms
ShiftOut(0xE1) ' F1 = 3dig F9 = 2digits
Set EnPin On
For num = 0 to 255
hundreds=num/100
temp=num-100*hundreds
tens=temp/10
ones=temp-tens*10
tens = tens AND 0x0f
rotate tens left simple
rotate tens left simple
rotate tens left simple
rotate tens left simple
temp = tens + ones
set Datapin off
Set PORTD.0 OFF
Set EnPin OFF
Wait 5 ms
ShiftOut(0XFF)
ShiftOut(hundreds)
ShiftOut(temp)
Set EnPin On
Set PORTD.0 ON
Wait 10 10ms
next
Goto Mainloop
' ----------------- Subrutines below --------------------------
Sub ShiftOut(DataByte)#NR
For clocks = 1 to 8
if DataByte.7 =1 then
set Datapin on
'set PORTD.1 on
end if
if DataByte.7 =0 then
set Datapin off
'set PORTD.1 off
end if
Rotate DataByte Left
Set ClkPin on
'set PORTD.2 on
Wait 5 ms
Set ClkPin off
'set PORTD.2 off
Wait 5 ms
Next
End Sub
could i change the code to 9 bit spi? thats what my lcd uses.
it would help to know what you are talking spi to. This routine only sent to the display. No receive as it is. To send 9bit spi you would splice the code on the front or back of the 8 bits. Is the 9 bit for master/slaves like 485?