Chào các bác. Các bác giúp e với e viết mãi code ko chạy được mô phỏng các bác chỉnh sửa giùm e. Đa tạ các bác
[ATTACH=CONFIG]28815[/ATTACH]
Code:
#define F_CPU 8000000UL #include <avr/io.h> #include <util/delay.h> #include <avr/interrupt.h> //*******************************Khai bao hang*************************************// #define led PORTB #define led_a 0b0111 #define led_b 0b1011 #define led_c 0b1101 #define led_d 0b1110 #define data PORTC #define do_C 0 //*******************************Khai bao bien**************************************// unsigned char font[13]={0xC0,0xF9,0xA4,0xB0, 0x99,0x92,0x82,0xF8, 0x80,0x90,0x9C,0xC6,0x8E}; // font hien thi so cho cac led unsigned char led_index=0, temp, nhiet_do, adc_data[2]; //**************************** Cau hinh chip *************************** void init (void) { DDRB=0x0F; DDRC=0xFF; //***************** KHOI TAO TIMER0 ************************** TCCR0|=(1<<CS01)|(1<<CS00); // CS02=0, CS01=1, CS00=0: chon Prescaler = 8 TCNT0=0x00; //gan gia tri khoi tao cho T/C0 OCR0=0x00; //************** KHOI TAO NGAT TIMER0 ************************** MCUCR=0x00; MCUCSR=0x00; TIMSK=0x41; // enable timer0 interupt //TIMSK=1<<TOIE0; //***************** Analog Comparator initialization ********************** ACSR=0x80; SFIOR=0x00; //****************** Set up ADC ******************************************* ADMUX=0|(0x20 & 0xff); // Set up ADC (Analog to Digital Converter) //ADCSRA=0xCB; ADCSRA|=(1<<ADEN)|(1<<ADSC)|(1<<ADIE)|(1<<ADPS1)|(1<<ADPS0); sei(); } //xU LY NGAT //******************* Ngat ADC ************************** ISR (ADC_vect) { static unsigned char input_index=0; adc_data[input_index]=ADCH; //adc_data[0] = ADCH if (++input_index > (1)) input_index=0; ADMUX=(0|(0x20 & 0xff))+input_index; _delay_us(300); ADCSRA|=0x40; } //***************** NGAT TIMER0 ***************************** ISR (TIMER0_VOF0_vect)//HIEN THI LED 7 BANG BANG NGAT TIMER0 { if(led_index==4) led_index=0; if(led_index==0) { led=led_a; data=font[(temp/10)%10]; } if(led_index==1) { led=led_b; data=font[temp%10]; } if(led_index==2) { led=led_c; data=font[10]; } if(led_index==3) { led=led_d; if(nhiet_do==do_C) data=font[11]; else data=font[12]; } led_index++; } void main (void) { init(); nhiet_do=do_C; _delay_ms(100); while(1) { // do nothing } }
Comment