AVR+7 szegmenses kijelzo
Pal Lukacs
ekegep at yahoo.com
Sat Oct 28 10:51:36 CEST 2006
Pal Lukacs <ekegep at yahoo.com> wrote:
Kozben en is dolgoztam a 7szegmenses meghajtason.az avr-progin,de meg nincs kesz a z elekotrnika hozza...
Namost az lenne a kerdesem hogy ha idoosztasos modszerrel 20ms -kent multiplexelek,akkor az 100 HZ-re jon ki?
Idezem az eddigi forraskodot..Jelzem meg nincs befejezve korant sincs..
#include <inttypes.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
//#include <avr/eeprom.h>
#define DISPLY_MPLEX_CTLR_DDR DDRD
#define DISPLY_MPLEX_CTLR PORTD
#define DISPLY_PORT_DDR DDRC
#define DISPLY_PORT PORTC
#define SEG_a 0x01
#define SEG_b 0x02
#define SEG_c 0x04
#define SEG_d 0x08
#define SEG_e 0x10
#define SEG_f 0x20
#define SEG_g 0x40
#define SEG_dot 0x80
//10ms & 2sec thersholds
#define CNT1_THRESHOLD 20
#define CNT2_THRESHOLD 4000
volatile unsigned int cnt1, cnt2;
unsigned char flag1 = 1;
unsigned char mplex_data = 1;
signed int temperature;
unsigned char disply_data;
unsigned char digits[] PROGMEM = {
(SEG_a | SEG_b | SEG_c | SEG_d | SEG_e | SEG_f), // 0
(SEG_b | SEG_c), // 1
(SEG_a | SEG_b | SEG_d | SEG_e | SEG_g), // 2
(SEG_a | SEG_b | SEG_c | SEG_d | SEG_g), // 3
(SEG_b | SEG_c | SEG_c | SEG_f | SEG_g), // 4
(SEG_a | SEG_c | SEG_d | SEG_f | SEG_g), // 5
(SEG_a | SEG_c | SEG_d | SEG_e | SEG_f | SEG_g), // 6
(SEG_a | SEG_b | SEG_c), // 7
(SEG_a | SEG_b | SEG_c | SEG_d | SEG_e | SEG_f | SEG_g), // 8
(SEG_a | SEG_b | SEG_c | SEG_d | SEG_f | SEG_g), // 9
(SEG_g), // -
(SEG_a)
};
unsigned char
seg7 (uint8_t _digit)
{
return pgm_read_byte_near (&digits[_digit]);
}
//timer2 : 256 (4 000 000 / 8) = 0,000512 --ovf.time-- * 20 = 0,01024 (=~10msec)
//0,000512 * 4000 = 2,048 sec
//atirni..
void
timer2_init ()
{
//ovf.int time = timer counter max / (fosc/prescaler)
//TIMSK |= (1 << TOIE1); //timer1 ovf. bekapcsolva
sei (); //global int. enable
}
/* idoosztas ...*/
SIGNAL (SIG_OVERFLOW1)
{
{
cnt1++;
cnt2++;
}
}
/*
disp1 = temperature/10;
disp2 = temperature%10;
*/
int
main ()
{
timer2_init ();
//i2c init...
/*ports init */
//..........
for (;;)
{
//2sec.onkent
if (cnt2 == CNT2_THRESHOLD)
{
//olvasas DS1621 -rol
//homerseklet szamitas ---> temperature
}
//10ms -onkent multiplex control
if (cnt1 == CNT1_THRESHOLD)
{
if (flag1)
{
if (mplex_data >= 2)
{
mplex_data = 1;
}
//disp1 bekapcsolva,az adat neki megy
DISPLY_MPLEX_CTLR = mplex_data; //00000001
if (temperature < 0)
disply_data = seg7 (10); //-
else if (temperature > 99)
disply_data = seg7 (11);
else
disply_data = seg7 (temperature / 10); //pl: 17C /10 = 1,7--> 1
DISPLY_PORT = disply_data;
flag1 = 0; //idokeres kikapcsolva
cnt1 = 0;
}
else
{
//disp2-re atkapcsolva(disp1 ki),az adat neki megy
DISPLY_MPLEX_CTLR = mplex_data * 2; //00000010
if (temperature < 0)
disply_data = seg7 (10); //-
else if (temperature > 99)
disply_data = seg7 (11);
else
disply_data = seg7 (temperature % 10); //pl: 17C %10 = 1,7--> 7
DISPLY_PORT = disply_data;
flag1 = 1;
cnt1 = 0;
}
}
}
return 0;
}
---------------------------------
How low will we go? Check out Yahoo! Messenger�s low PC-to-Phone call rates.
---------------------------------
Check out the New Yahoo! Mail - Fire up a more powerful email and get things done faster.
More information about the Elektro
mailing list