Mike is correct
try this , it works on a 12f1822
note leds 2,3 and 4 show random crap since nothing is written to them
and not using lat regs is asking for trouble
nearly forgot dispnum = 146 ' "2" (Common anode) (10010010)
not on my display
dispnum = $5b ' "2" (Common anode) (01011101)
Code:
OSCCON = %01111000 '16MHz HF, software PLL disabled
DEFINE OSC 16
'Port direction
TRISA = %001000 'A.3 is input, rest are outputs.
CM1CON0 = 0 'Disable comparator
ANSELA = 0 'Disable A to D
'List of Aliases
LED var PortA.0
DIO var LATA.1
CLK var LATA.2
TrisDIO VAR TrisA.1
'List of variables
Cnt var byte
ByteToSend var byte 'Command or Data byte to be sent
DispCmd var byte
dispcmd = 64 'Command byte for displaying characters starting with the leftmost digit (0b01000000)
Brt8Cmd var byte
brt8cmd = 143 'Command byte for display on with maximum brightness (0b10001111)
Dig1Addr var byte
dig1addr = 192 'Address of digit 1 (left most) (0b11000000)
DispNum var byte
dispnum = $5B' "2" (Common anode) (10010010)
'Diagnostic routine
DiagRoutine:
CLK=1
for cnt = 1 to 4 'Blink LED 4 times.
led = 1 : pause 100
led = 0 : pause 100
next cnt
goto start
'Subroutines
StartCondition:
clk = 0
dio = 1
clk = 1
pauseus 50
dio = 0 'DIO goes low when CLK is high.
pauseus 50
return
SendTheByte:
clk = 0
for cnt = 0 to 7 'Send 8 bits of data, starting with the LSB.
dio = bytetosend.0(cnt)
pauseus 50
clk = 1
pauseus 50
clk = 0
Next cnt
'dio = 1
Trisdio = 1 ' Set Data pin direction to input to receive ACK.
pauseus 50
clk = 1
pauseus 50
clk = 0
Trisdio = 0 ' Set Data pin direction back to output.
return
StopCondition:
clk = 0
dio = 0
clk = 1
pauseus 50
dio = 1 'DIO goes high when CLK is high.
pauseus 50
return
START:
bytetosend = dispcmd 'DispCmd (01000000) (64) = Command byte with auto increment sent before sending the digit data
gosub startcondition
gosub sendthebyte
gosub stopcondition
bytetosend = dig1addr 'Dig1Addr (11000000) (192) = Address of digit 1 (leftmost digit)
gosub startcondition
gosub sendthebyte
bytetosend = dispnum ' Number "2" (10010010) (146) (Common anode)
gosub sendthebyte
gosub stopcondition
bytetosend = brt8cmd 'Brt8Cmd (10001111) (143) = Command for Display On with Maximum Brightness
gosub startcondition
gosub sendthebyte
gosub stopcondition
END
Bookmarks