Sunday, October 17, 2010

GCBASIC Tutorial 2 part 2: 3 wires 7 segment LED display using open source PIC compiler



As in part 1 I have show how to program a single 7 segments with 3 wires. In this tutorial I have modify the last circuit by add-on another two 7 segments and two IC 4094 Shift register.

The three 7 segment and three IC 4094 Shift register have been connected as picture above. Take note on the CLK and STB pin of the three IC 4094. There are connecting each others with RB1 and RB2 of PIC respectively. The purpose of connection is to sharing Clock and Strobe signal output from PIC.

However the data output from PIC is only connected to pin2 of U2. At the same time pin 2 of U3 and U4 are cascading by connecting QS of the previous 4094. This can be explained that the 8 bit data of U2 is cascading to U3 and so on.

'A program to flash two LEDs on PORTB, bits 0 and 1

'Chip model
#chip 16F84a, 4

#define data PORTB.0 'set as data
#define clock PORTB.1 'set as clock
#define strobe PORTB.2 'set as strobe

dim x as byte

'Set the pin directions
dir PORTB out


'Main routine
Start:

set data off 'put data low
for loopcounter = 1 to 8
PulseOut clock, 10 ms
PulseOut strobe, 10 ms
next


for x = 1 to 10 ‘#1
readtable tsegment2,x,segment
gosub display
next

table tsegment
b'01111110 '#0
b'00110000 '#1
b'01101101 '#2
b'01111001 '#3
b'00110011 '#4
b'01011011 '#5
b'01011111 '#6
b'01110000 '#7
b'01111111 '#8
b'01111011 '#9
end table

end

display: #2
for loopcounter = 1 to 7
nsegment = segment % 2
data = nsegment
PulseOut clock, 10 ms
segment = segment / 2
next

data = segment
PulseOut clock, 10 ms
PulseOut strobe, 100 ms
return

The program above is identical with previous program but only two parts was add-on. At #1 I use for..next cycle to have 7 segment to shows number from 0 to 9. It could produce only single number at one time. The readtable function is used to call a number arrangement which is stored in tsegment table. The number arrangements are in binary and it’s responding to the arrangement of the 7 segment.

At #2 I used label to display number on 7 segments. The name of the label is Display. The line inside of display label is identical line from previous program at #4. The GOSUB function had used inside for..next loop at #1 in order to jump into display label and return back after finish their job.

When you run the program it will produce the number at first 7 segments only. A few second after that the number will shift to second 7 segments. However first 7 segment will produce a new number. Once again a few second after that the number at second 7 segments will shift to third 7 segments. The second 7 segment will replace with the number previously at first 7 segments.

The shift number can be explained due to 4094 are connected in cascading. Actually the PIC sends 8 bit data to the U2 only. The U2 then shift the previous data into U3 after received new data from PIC. The U3 will store the data and display on 7 segments when STB is high. It then repeated the process for the rest of 4094.

1 comment:

  1. salam bro
    kalo nk wat 1 je 7 segment cm ne lak
    jd kn dia counter up or conter down

    ReplyDelete