7 Segment LED sketches

This page is a demo/sketch in response to the posting in my guestbook:

From: Bob McMillan Email: ...
Posted on: Wednesday, March 13, 2002, 07:56 AM

Does anyone have a circuit and code for a simple countdown timer? I am trying in vain to write one for a disabled group. It needs to count down from 2 hours 30 minutes and display on 3 or 4 7 segment displays. I have been given PIC16f84 chips for the job. Thanks bob

Well, my shipping forecast timer has a BCD count up timer, and this sketch is a stripped down version that outputs the count on 7 segment LCD displays. It does nothing else. When reset, it starts counting up from 02:30.

In the diagram below, only two of the displays are shown. Connect 4 displays, with the segments in parallel. Each display is multiplexed, so only one display is on at a time.

If each segment is driven via a 470R resistor, then if all segments are on, then the common cathode current is about 70mA, so needs a transitor to boost the current, as the max current that the PIC can sink is about 25mA.

If its hfe is > 100, then the base current of 2 mA should be enough and can be driven by a 2K2 resistor.

The Segments should be connected to PortB to match the definitions below:

;	 _
;	|_|
;	|_|
;
	
;	 
;	  - a
;	f| |b
;	  - g
;	e| |c
;         - d
;	
; Connect PB6 to a 
; Connect PB0 to g 
; Connect PB7 to dp?

;			;     76543210
;			;      abcdefg
SegmentsforDigit0	EQU B'01111110' ; a,b,c,d,e,f, 
SegmentsforDigit1	EQU B'00110000' ;  ,b,c, , , , 
SegmentsforDigit2	EQU B'01101101' ; a,b, ,d,e, ,g
SegmentsforDigit3	EQU B'01111001' ; a,b,c,d, , ,g
SegmentsforDigit4	EQU B'00110011' ;  ,b,c, , ,f,g
SegmentsforDigit5	EQU B'01011011' ; a, ,c,d, ,f,g
SegmentsforDigit6	EQU B'01011111' ; a, ,c,d,e,f,g
SegmentsforDigit7	EQU B'01110000' ; a,b,c, , , , 
SegmentsforDigit8	EQU B'01111111' ; a,b,c,d,e,f,g
SegmentsforDigit9	EQU B'01111011' ; a,b,c,d, ,f,g
SegmentsforDigitA	EQU B'01110111' ; a,b,c, ,e,f,g
SegmentsforDigitB	EQU B'00011111' ;  , ,c,d,e,f,g
SegmentsforDigitC	EQU B'01001111' ; a, , ,d,e,f,g
SegmentsforDigitD	EQU B'00111101' ;  ,b,c,d,e, ,g
SegmentsforDigitE	EQU B'01001111' ; a, , ,d,e,f,g
SegmentsforDigitF	EQU B'01000111' ; a, , , ,e,f,g

; port A control bits
segDisplaymM	EQU 0
segDisplayMm	EQU 1
segDisplayhH	EQU 2
segDisplayHh	EQU 3

The Code is contained in: codecd001.zip ( 19K ).

 

If clocked at 4Mhz, instead of 32kHz, this is 125 faster, so the minute counts last 0.5 seconds and the display looks okay.

It has been tested to this extend. A PIC16F84 was programmed and an old LED calculator display was seen to count up, through the 24 hour clock.

I used BC182L transistors and resistor values of 820R, on my bread board.

I used a 4Mhz ceramic resonator as these are easy to connect.

There is no code to set the time, and it does not count down.

Doug Rice, Copyright 2002.

Last Updated 17th March 2002