This serial display receives every seconds data, 1200 baud of an other PIC

I'm trying to convert this seconds (0 to 9999) into Minutes, Seconds... on the LED display.

But, i'm missing the minutes ?!

Thanks for any help!

Name:  dsp_01.jpg
Views: 973
Size:  598.0 KB


@ device pic16f687,intrc_osc_noclkout,bod_off,pwrt_on,wdt_o ff,mclr_on,protect_on

DEFINE OSC 4 ' Set Speed (INT OSC)
DEFINE HSER_RCSTA 90h ' Enable USART receive
DEFINE HSER_TXSTA 24h ' TXSTA=%00100100 TX enable, BRGH=1 for high-speed
' DEFINE HSER_TXSTA 20h ' TXSTA=%00100000 TX enable, BRGH=0 for low-speed
' DEFINE HSER_SPBRG 207 ' 1200 Baud @ 4MHz, 0.17%
DEFINE HSER_BAUD 1200 ' Set Baudrate to 1200
DEFINE HSER_CLROERR 1 ' Auto clear over-run errors


' setting for PIC '687
OSCCON = %01100111 ' Internal Clock set to 4 MHZ ?!?
INTCON = 0 ' Disable interrupts
ADCON1 = 7
ANSEL = 0 ' Analog to Digital
ANSELH = 0 ' Analog to Digital
TRISA = %00000000
TRISB = %00000000
TRISC = %00000000
PORTA = 0
PORTB = 0
PORTC = 0

B0 var byte ' Segment counter
W1 var word ' VAR for received bytes
W2 var word
D1 var word
RCIF var PIR1.5 ' USART received character

w1 = 0 ' Start Val

pause 250 ' Wait for Power_Up


' ----- [ Main ] --------------------------------------------------------------

Main:

IF RCIF = 1 THEN ' If RCIF = 1 there's new char in RCREG

hserin [WAIT("@"),W1.HIGHBYTE,W1.LOWBYTE] ' Get char from UART


' *** convert received seconds 0-999 into Minutes & Seconds ***

W2 = W1 / 60 ' Minutes = W1 / 60
W1 = W1 // 60 ' seconds = W1 // 60

gosub Display
Else
gosub Display

endif


goto Main


display:

D1 = W1 ' Put W1 entry value in D1
B0 = D1 / 100 ' Find number of hundreds
D1 = D1 // 100 ' Remove hundreds from W1

Gosub bin2seg ' Convert number to segments


poke PortC,%10000000 ' DP on first LED
high PortA.2 ' Minutes LED
Pause 3 ' Leave it on 3 ms
low PortA.2 ' Turn off to prevent ghosting

B0 = D1 / 10 ' Find number of tens
D1 = D1 // 10 ' Remove tens from W1

Gosub bin2seg ' Convert number to segments

Poke PortC,B0 ' Send segments to LED
high PortA.1
Pause 3 ' Leave it on 3 ms
low PortA.1 ' Turn off to prevent ghosting

B0 = D1 ' Get number of ones

Gosub bin2seg ' Convert number to segments

Poke PortC,B0 ' Send segments to LED
High PortA.0
Pause 3 ' Leave it on 3 ms
Low PortA.0 ' Turn off to prevent ghosting


Return ' Go back to caller


bin2seg:

' Convert binary number in B0 (0 t/m 9) to segments for LED
Lookup B0,[$3F,$6,$5B,$4F,$66,$6D,$7D,$7,$7F,$6F],B0


Return


' ----- [ E N D ] -------------------------------------------------------------

END