Datasheet

Programming PIC Microcontrollers in BASIC - mikroElektronika
its mask must be sent to PORTB. For example, if we need to display "1", segments b and c must be set to 1 and the rest
must be zero. If (according to the scheme above) segments b and c are connected to the first and the second pin of
PORTB, values 0000 and 0110 should be set to PORTB. Thus, mask for number "1" is value 0000 0110 or 06
hexadecimal. The following table contains corresponding mask values for numbers 0-9:
Digit Seg. h Seg. g Seg. f Seg. e Seg. d Seg. c Seg. b Seg. a HEX
0 0 0 1 1 1 1 1 1 $3F
1 0 0 0 0 0 1 1 0 $06
2 0 1 0 1 1 0 1 1 $5B
3 0 1 0 0 1 1 1 1 $4F
4 0 1 1 0 0 1 1 0 $66
5 0 1 1 0 1 1 0 1 $6D
6 0 1 1 1 1 1 0 1 $7D
7 0 0 0 0 0 1 1 1 $07
8 0 1 1 1 1 1 1 1 $7F
9 0 1 1 0 1 1 1 1 $6F
You are not, however, limited to displaying digits. You can use 7seg Display Decoder, a built-in tool of mikroBasic, to
get hex code of any other viable combination of segments you would like to display.
But what do we do when we need to display more than one digit on two or more displays? We have to put a mask on one
digit quickly enough and activate its transistor, then put the second mask and activate the second transistor (of course, if
one of the transistors is in conducting mode, the other should not work because both digits will display the same value).
The process is known as “multiplexing”: digits are displayed in a way that human eye gets impression of simultaneous
display of both digits – actually only one display emits at any given moment.
Now, let’s say we need to display number 38. First, the number should be separated into tens and ones (in this case,
digits 3 and 8) and their masks sent to PORTB. The rest of the program is very similar to the last example, except for
having one transition caused by displaying one digit after another:
program seven_seg_twodigits
dim v as byte
dim por1 as byte
dim por2 as byte
sub procedure interrupt
begin
if v = 0 then
PORTB = por2 ' Send mask of tens to PORTB
http://www.mikroelektronika.co.yu/english/product/books/picbasicbook/07.htm (6 sur 16)05/11/2004 02:27:45