با سلام.این برنامه قسمت 17 اموزش avr جناب کی نزاد هست که جا داره همین جا ازشون کمال تشکر رو به جا بیارم.لطفا کسی این برنامه رو توضیح بدهید. :read:
همینطور خط زیر 11 هارو برای چی گذاشتیم؟
//------------------------------------------------------------------------------------------------------------------
از اینجا به بعدشم خوب نمی فهمم.
اضافه شده در تاریخ :
:question:
Written by Ozhan KD - www.KnowledgePlus.ir Pressing a key displays the keyboard defined character on 7segments from left to right
-|--|--|--|-- PB0
-|--|--|--|-- PB1
-|--|--|--|-- PB2
PB3 PB5
PB4 PB6
PC0 --- a
PC1 --- b
PC2 --- c
PC3 --- d
PC4 --- e
PC5 --- f
PC6 --- g
PC7 --- dp
PA0 --- LEDs_select
PA1 --- DIGIT0_select
PA2 --- DIGIT1_select
PA3 --- DIGIT2_select
PA4 --- DIGIT3_select
PA5 --- DIGIT4_select
PA6 --- DIGIT5_select
*/
-|--|--|--|-- PB0
-|--|--|--|-- PB1
-|--|--|--|-- PB2
PB3 PB5
PB4 PB6
PC0 --- a
PC1 --- b
PC2 --- c
PC3 --- d
PC4 --- e
PC5 --- f
PC6 --- g
PC7 --- dp
PA0 --- LEDs_select
PA1 --- DIGIT0_select
PA2 --- DIGIT1_select
PA3 --- DIGIT2_select
PA4 --- DIGIT3_select
PA5 --- DIGIT4_select
PA6 --- DIGIT5_select
*/
#include <mega32.h>
#include <delay.h>
#include <delay.h>
خط زیر رو برای چی فرا خواندیم؟
#define nokey_code 12
// 7 segment codes
flash unsigned char display_codes[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6 f,0x00,0x40};
//keyboard codes
flash unsigned char keyboard_codes[]={0x76,0x6E,0x5E,0x3E,0x75,0x6D,0x5D,0x3D,0x73,0x6 B,0x5B,0x3B};
flash unsigned char display_codes[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6 f,0x00,0x40};
//keyboard codes
flash unsigned char keyboard_codes[]={0x76,0x6E,0x5E,0x3E,0x75,0x6D,0x5D,0x3D,0x73,0x6 B,0x5B,0x3B};
همینطور خط زیر 11 هارو برای چی گذاشتیم؟
volatile unsigned char data[]={11,11,11,11,11,11},leds=0; // initial values for display ( ------ )
volatile unsigned char key_code=nokey_code;
void main()
{
unsigned char i=5;
unsigned char temp_key_code,old_key_code=nokey_code;
DDRC=(1<<DDC7)|(1<<DDC6)|(1<<DDC 5)|(1<<DDC4)|(1<<DDC3)|(1<<DDC2) |(1<<DDC1)|(1<<DDC0);
PORTA=(1<<PORTA6)|(1<<PORTA5)|(1<&l t;PORTA4)|(1<<PORTA3)|(1<<PORTA2)|(1&l t;<PORTA1)|(1<<PORTA0);
DDRA=(1<<DDA6)|(1<<DDA5)|(1<<DDA 4)|(1<<DDA3)|(1<<DDA2)|(1<<DDA1) |(1<<DDA0);
//initialize timer
OCR0=124;
TCCR0=(1<<WGM01)|(1<< CS01);
TIMSK=(1<<OCIE0);
#asm("sei"
;
while(1)
{
// Update key code.
// This is necessary because of possible change of key code during loop
temp_key_code=key_code;
if (temp_key_code!=nokey_code)leds=1; // Turn on LED if any key pressed
else leds=0;
if (temp_key_code!= old_key_code)
{
old_key_code=temp_key_code;
if (temp_key_code!=nokey_code)
{
data[i]=temp_key_code;
چرا i رو 5 تعریف کردهایم؟ volatile unsigned char key_code=nokey_code;
void main()
{
unsigned char i=5;
unsigned char temp_key_code,old_key_code=nokey_code;
DDRC=(1<<DDC7)|(1<<DDC6)|(1<<DDC 5)|(1<<DDC4)|(1<<DDC3)|(1<<DDC2) |(1<<DDC1)|(1<<DDC0);
PORTA=(1<<PORTA6)|(1<<PORTA5)|(1<&l t;PORTA4)|(1<<PORTA3)|(1<<PORTA2)|(1&l t;<PORTA1)|(1<<PORTA0);
DDRA=(1<<DDA6)|(1<<DDA5)|(1<<DDA 4)|(1<<DDA3)|(1<<DDA2)|(1<<DDA1) |(1<<DDA0);
//initialize timer
OCR0=124;
TCCR0=(1<<WGM01)|(1<< CS01);
TIMSK=(1<<OCIE0);
#asm("sei"

while(1)
{
// Update key code.
// This is necessary because of possible change of key code during loop
temp_key_code=key_code;
if (temp_key_code!=nokey_code)leds=1; // Turn on LED if any key pressed
else leds=0;
if (temp_key_code!= old_key_code)
{
old_key_code=temp_key_code;
if (temp_key_code!=nokey_code)
{
data[i]=temp_key_code;
if (--i==0xff) i=5;
}
}
}
}
}
}
}
//------------------------------------------------------------------------------------------------------------------
از اینجا به بعدشم خوب نمی فهمم.
interrupt [TIM0_COMP] void timer0_compare_isr(void)
{
static unsigned char select=0;
static unsigned char x20=0;
unsigned char temp , i;
// Turn off all 7segments and LEDs
PORTA|=(1<<PORTA6)|(1<<PORTA5)|(1<& lt;PORTA4)|(1<<PORTA3)|(1<<PORTA2)|(1& lt;<PORTA1)|(1<<PORTA0);
if (select)PORTC =display_codes[data[select-1]];
else PORTC=leds;
PORTA &=~(1<<select);
if(++select==7)select=0;
if (++x20==20)
{
x20=0;
DDRB=(1<<DDB2)|(1<<DDB1)|(1<<DDB 0);
PORTB=(1<<PORTB6)|(1<<PORTB5)|(1<&l t;PORTB4)|(1<<PORTB3);
delay_us(5); // delay for signal stablization
temp=(PINB & 0X78);
DDRB=(1<<DDB6)|(1<<DDB5)|(1<<DDB 4)|(1<<DDB3);
PORTB=(1<<PORTB2)|(1<<PORTB1)|(1<&l t;PORTB0);
delay_us(5); // delay for signal stablization
temp |=(PINB & 0X07);
for(i=0;i<12;i++)
{
if(temp==keyboard_codes[i])
{
key_code=i;
break;
}
else key_code=nokey_code;
}
}
}
{
static unsigned char select=0;
static unsigned char x20=0;
unsigned char temp , i;
// Turn off all 7segments and LEDs
PORTA|=(1<<PORTA6)|(1<<PORTA5)|(1<& lt;PORTA4)|(1<<PORTA3)|(1<<PORTA2)|(1& lt;<PORTA1)|(1<<PORTA0);
if (select)PORTC =display_codes[data[select-1]];
else PORTC=leds;
PORTA &=~(1<<select);
if(++select==7)select=0;
if (++x20==20)
{
x20=0;
DDRB=(1<<DDB2)|(1<<DDB1)|(1<<DDB 0);
PORTB=(1<<PORTB6)|(1<<PORTB5)|(1<&l t;PORTB4)|(1<<PORTB3);
delay_us(5); // delay for signal stablization
temp=(PINB & 0X78);
DDRB=(1<<DDB6)|(1<<DDB5)|(1<<DDB 4)|(1<<DDB3);
PORTB=(1<<PORTB2)|(1<<PORTB1)|(1<&l t;PORTB0);
delay_us(5); // delay for signal stablization
temp |=(PINB & 0X07);
for(i=0;i<12;i++)
{
if(temp==keyboard_codes[i])
{
key_code=i;
break;
}
else key_code=nokey_code;
}
}
}
اضافه شده در تاریخ :
:question:
دیدگاه