2
Practical – 01 Toggle Port LED Aim : Write a program in embedded C programming language to alternately ON/OFF …show more content…
Components Used: i)AT90S8535 Micro controller ii)LED‟S iii)Ground Code: #include int timeCount = 0; interrupt[TIM0_OVF] void timer0_ovf_isr(void) { TCNT0 = 6; if(++timeCount == 1000) { PORTA =PORTA ^ 0x01; timeCount = 0; } } void main(void) { DDRA = 0x01; PORTA = 0x01; TCCR0 = 0x02; TIMSK = 0x01; #asm("sei"); while(1); } Description: A variable timecount is initialized to 0. In the main function the LSB of PORTA is chosen for output and it is set to 1. Then the TIMER COUNTER CONTROL REGISTER (TCCR0) is initialized in such a way that divide by 8 (CK/8)clock source is selected again the “timer interrupt mask is set to enable the timer0 counter. “#asm” is a assembly language instruction „sei‟ stands for set enable interrupts to enable all the interrupts. Finaly ainfinite while loop.Then the function with keword interrupt is created.This function will be called automatically when the timer0 overflow interrupt takes place. This function returns nothing, since it is not called by any function and you cant pass any thing to function for the same reason .The timer0 is initialized to 6 in this function .As we have chosen ck/8 system as mentioned above and the clock frequency is 4 Mhz that‟s why 4/8 Mhz so 500 Khz(0.5 Mhz) will be the effective frequency so for one tick of counter 1/0.5 micro sec are required(1/freq.= time) that equals to 2 micro secondes. A timer can