PDA

View Full Version : 3 digit 7-Seg serial Display



Gevo
- 17th December 2019, 14:58
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!

8794


@ 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

CuriousOne
- 26th December 2019, 14:37
Nice display, where did you get it?

Gevo
- 9th January 2020, 15:41
I have make this !

Ioannis
- 10th January 2020, 09:19
Not clear what you mean.

Ioannis

gebillpap
- 10th January 2020, 11:50
I think you forget to put minutes in the minutes LED although you do remember it for the rest digits .So try this..
........
........
poke PortC,%10000000 ' DP on first LED
Poke PortC,B0 ' Send segments to LED
Poke PortC.7,1
high PortA.2 ' Minutes LED
Pause 3 ' Leave it on 3 ms
low PortA.2 ' Turn off to prevent ghosting
........
........

Gevo
- 14th January 2020, 15:18
[QUOTE=Ioannis;144615]Not clear what you mean.

Ioannis,

I'm missing the minutes on the first LED dsp... :o

Amoque
- 20th January 2020, 17:03
Perhaps I am not following your idea clearly, but it seems the problem is bigger than you state...

Up until 599 seconds the display may read minutes and seconds like: M.SS with no problem, but with 10 minutes, then seconds (or minutes) must be only one digit. You may choose to change the display so that at low times, - less the 599 seconds you display M.SS but at 600 seconds the display becomes MM.S. This will require two display routines. Or, you may display minutes as hexadecimal and use A, B, C, D, E, F for values greater than 10. Then you may display M.SS for all values up to 999 seconds with only 1 minutes digit.

Once you have determined how to display your time consistently, then recheck the datasheet of your display, it seems strange to me that a serial display will require more than some string data to display numbers. I would imagine some SEROUT Pin, Mode, (Item{,Item}) statement would work - at least try this through the built in serial function (DEBUG) in PicBasic to be sure all that you intend to send to the display is correct.

HTH