Forum Replies Created
Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
BhanuKiran ChaluvadiParticipant
/* Here is the actual Working Progam, Controlling Servo Using TIMER0 . SO that we can use Timer1 for other Purpose */
#include <avr/io.h>#include <util/delay.h>#include <avr/interrupt.h>volatile uint8_t tot_overflow;void timer0_init(){TCCR0 |= (1<<WGM01) | (1<<WGM00) | (1<<CS02) ; // Fast PWM CTC mode, Prescaling of 256TCNT0 = 0 ;OCR0 = 249;TIMSK |= (1<<OCIE0) ;sei();}ISR (TIMER0_COMP_vect){tot_overflow++;if(tot_overflow==5){PORTA |= (1<<PA0) | (1<<PA1) | (1<<PA2) ;tot_overflow=0;}}int main (void){DDRA |= (1<<PA0) | (1<<PA1) | (1<<PA2) ;timer0_init();tot_overflow=0;while(1){if (TCNT0>=15 && TCNT0<=145 && tot_overflow==0){if (TCNT0 >= 23 && bit_is_set(PORTA, PINA0) ) PORTA &= ~(1<<PINA0);if (TCNT0 >= 78 && bit_is_set(PORTA, PINA1) ) PORTA &= ~(1<<PINA1);if (TCNT0 >= 133 && bit_is_set(PORTA, PINA2) ) PORTA &= ~(1<<PINA2);}}}BhanuKiran ChaluvadiParticipantThanks for u r help sir …I made 2 mistakes
1.Using CS12 for Prescaling which has to be CS02 ;
2. It has to be ISR(TIMER0_COMP_vect) not ISR(TIMER0_COMPA_vect) ;
BhanuKiran ChaluvadiParticipantUnfortunately, i posted it wrongly sir . In the actual program i used TCNT0 every where. Now i corrected the program posted above . Could u please help me in finding mistake sir .
BhanuKiran ChaluvadiParticipantThank u Sir…
This is the final code and its working…
// Program to interface LCD in 4 bit mode with AVR microcontroller//#define F_CPU 12000000UL#include<avr/io.h>#include<util/delay.h>#include<inttypes.h>#define rs PD3#define rw PD6#define en PB4void lcd_init(void);void dis_cmd(char);void dis_data(char);void lcdcmd(char);void lcddata(char);int main(void){unsigned char data0[11]=”JAI”;unsigned char data1[10]=”BALAYYA”;int i=0;DDRA=0xFF;DDRD=0xFF; //modifiedDDRB=0xFF; //modifiedlcd_init();while(data0!=’