In another life I have probably been molested by some integrated control led, can not be explained otherwise my groundless antipathy towards them. A faint glimmer of explanation may come from the fact that for the applications to which I devoted myself lately the number of ports available on average in the pic I had available was entirely disproportionate. Tantovale then use the LED display (but I did get carried away with arrays ...) by connecting each segment to a pin, so therefore to avoid getting those nasty interfaces and especially the result of having complete control of the output view , moreover, entirely in software.
After this long and tedious introduction to the application come to basics: a good "counter".
The last time I saw a "real" has been on a cruise, where the effective charge of tours at each step of individual clicked on this mechanical gadgets making sure not to plant so no one around Greece.
the carrying out of an electronic implementation allows you to experiment with different aspects of gadgets and heavily customized programs including:
- eprom storage on the current results in order not to lose the bounce-off
- function buttons (1 click = 1 number, regardless of time pressure)
- Direct control of the segments led
- Any mini-visualizations obtained with 2x7segmenti
The pic chosen, mostly because I had to laze around 2, is the 16F876A. The displays are common-anode, and then to turn on a segment will be necessary to a low logic value.
In the past, I happened to use to display segments without proof, making sure that does not involve soldering the same as usual with normal LEDs, but the resistors are sometimes like the hat in the desert: if co domentichiamo to put it to the brain and begin to cook sbarellare! Having noticed the sudden malfunction and reset the microcontroller, probably caused by the passage of too much current I conservatively put up any resistance even cathode, resulting in a much improved system stability.
From the perspective of the firmware versions between pro after many vicissitudes, mica-pro, C, Basic and Pascal, and especially quantomento irregular numbering of the development of MikroElettronica I decided to fall back on the last release available in the free version BASIC language.
aside some features "play" let's concentrate on the work of goddamn integrated control, which in this program is carried out by the function AccendiNumero already customized to generate output directed to display 2. The number input is split into tens and units, and subsequently transformed into combinations of LEDs representing the number needed. In the bottom of the post the complete source is available.
The counting function in
Some initial test of piloting the display
program counter
symbol = Decine_A PORTC.1
symbol Decine_B = PORTC.2
symbol Decine_C = PORTB.5
symbol Decine_D = PORTB.6
symbol Decine_E = PORTB.7
symbol Decine_F = PORTC.0
symbol Decine_G = PORTA.4
symbol Decine_Punto = PORTB.4
symbol Unita_A = PORTC.5
symbol Unita_B = PORTC.4
symbol Unita_C = PORTB.1
symbol Unita_D = PORTB.2
symbol Unita_E = PORTB.3
symbol Unita_F = PORTC.6
symbol Unita_G = PORTC.3
symbol Unita_Punto = PORTC.7
dim iCounter as byte
dim iValore as byte
const ms_speed=150
sub procedure test_porte()
[......]
sub procedure SpegniTutto()
Decine_A=1
Decine_B=1
Decine_C=1
Decine_D=1
Decine_E=1
Decine_F=1
Decine_G=1
Decine_Punto=1
Unita_A=1
Unita_B=1
Unita_C=1
Unita_D=1
Unita_E=1
Unita_F=1
Unita_G=1
Unita_Punto=1
end sub
sub procedure AccendiTutto()
Decine_A=0
Decine_B=0
Decine_C=0
Decine_D=0
Decine_E=0
Decine_F=0
Decine_G=0
Decine_Punto=0
Unita_A=0
Unita_B=0
Unita_C=0
Unita_D=0
Unita_E=0
Unita_F=0
Unita_G=0
Unita_Punto=0
end sub
sub procedure AccendiNumero(dim number as byte)
united as byte dim
ten as byte dim
units = number mod 10
tens = (number - units)
select ten houses
case 10
Decine_A = 1
Decine_B = 0
Decine_C = 0
Decine_D = 1
Decine_E = 1
Decine_F=1
Decine_G=1
case 20
Decine_A=0
Decine_B=0
Decine_C=1
Decine_D=0
Decine_E=0
Decine_F=1
Decine_G=0
case 30
Decine_A=0
Decine_B=0
Decine_C=0
Decine_D=0
Decine_E=1
Decine_F=1
Decine_G=0
case 40
Decine_A=1
Decine_B=0
Decine_C=0
Decine_D=1
Decine_E=1
Decine_F=0
Decine_G=0
case 50
Decine_A=0
Decine_B=1
Decine_C=0
Decine_D=0
Decine_E=1
Decine_F=0
Decine_G=0
case 60
Decine_A=0
Decine_B=1
Decine_C=0
Decine_D=0
Decine_E=0
Decine_F=0
Decine_G=0
case 70
Decine_A=0
Decine_B=0
Decine_C=0
Decine_D=1
Decine_E=1
Decine_F=1
Decine_G=1
case 80
Decine_A=0
Decine_B=0
Decine_C=0
Decine_D=0
Decine_E=0
Decine_F=0
Decine_G=0
case 90
Decine_A=0
Decine_B=0
Decine_C=0
Decine_D=0
Decine_E=1
Decine_F=0
Decine_G=0
case 0
Decine_A=0
Decine_B=0
Decine_C=0
Decine_D=0
Decine_E=0
Decine_F=0
Decine_G=1
homes else
Decine_A = 1
Decine_B = 1
Decine_C = 1
Decine_D = 1
Decine_E = 1
Decine_F = 1
Decine_G = 0
end select
select homes combined
case 1
Unita_A = 1
Unita_B=0
Unita_C=0
Unita_D=1
Unita_E=1
Unita_F=1
Unita_G=1
case 2
Unita_A=0
Unita_B=0
Unita_C=1
Unita_D=0
Unita_E=0
Unita_F=1
Unita_G=0
case 3
Unita_A=0
Unita_B=0
Unita_C=0
Unita_D=0
Unita_E=1
Unita_F=1
Unita_G=0
case 4
Unita_A=1
Unita_B=0
Unita_C=0
Unita_D=1
Unita_E=1
Unita_F=0
Unita_G=0
case 5
Unita_A=0
Unita_B=1
Unita_C=0
Unita_D=0
Unita_E=1
Unita_F=0
Unita_G=0
Case 6
Unita_A=0
Unita_B=1
Unita_C=0
Unita_D=0
Unita_E=0
Unita_F=0
Unita_G=0
case 7
Unita_A=0
Unita_B=0
Unita_C=0
Unita_D=1
Unita_E=1
Unita_F=1
Unita_G=1
case 8
Unita_A=0
Unita_B=0
Unita_C=0
Unita_D=0
Unita_E=0
Unita_F=0
Unita_G=0
case 9
Unita_A=0
Unita_B=0
Unita_C=0
Unita_D=0
Unita_E=1
Unita_F=0
Unita_G=0
case 0
Unita_A=0
Unita_B=0
Unita_C=0
Unita_D=0
Unita_E=0
Unita_F=0
Unita_G=1
end select
end sub
main:
INTCON = 0
ADCON0 = %11000000
ADCON1 = 000111
trisA.0 = 1
trisA.1 = 1
trisA.2 = 1
trisA.5 = 1
trisA.4 = 0
TRISB = 0x00
Trisch = 0x00
portA.4 = 1
PORTB =% 11111111
PORTC =% 11111111
test_porte ()
SpegniTutto
delay_ms (1000)
iValore=EEPROM_read(0x02)
if iValore < 0 then iValore = 0
end if
while TRUE
if (Button(PORTA,1,1,1)) then
Dec(iValore)
while porta.1=1
wend
end if
if (Button(PORTA,2,1,1)) then
iValore=0
while porta.2=1
wend
end if
if (Button(PORTA,3,1,1)) then
Inc(iValore)
while porta.3=1
wend
end if
if (iValore=100) or (iValore < 0) then iValore=0
end if
AccendiNumero(iValore)
EEPROM_write (0x02, iValore)
wend
0 comments:
Post a Comment