caan any body cross check my logic in c programming

Status
Not open for further replies.

kaleem

New Member
hi friends,my project is a temperature sensor device controlled by Atmel tiny here is the c program.I have checked this program on AVR simulator and its working fine on simulator,i have adevelopment board of olimex when i tested this program and made the led to blink its continously blinking for ever,i mean its haing a watchdog timer function for a period of about 2 minutes,as far this function led should blink for 2 mins and then reset should occur

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/delay.h>
#include <avr/signal.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/iom128.h>
#define F_CPU=16;
void data_send(void);
void init(void);
void delay_loop(unsigned char);
unsigned char data[3]; // data packet
unsigned char counter;
unsigned char i;
unsigned char x;
unsigned char timecount = 0;
unsigned char reset_no;
/* ADC interrupt service routine*/
SIGNAL(SIG_ADC)
{ //data[1] =ADCH; // read MSB into variable
data[1]=0xaa;
PORTB = 0X00; // disable temp sensor
data_send(); // send packet data
ADCSRA= 0x00; // disable ADC
WDTCR= 0x0F; // WDT enable;reset mode;
MCUCR= 0x31; // enable power down sleep ;
//sleep_mode();
}

void delay_loop(unsigned char us)
{for(;us>0;us--)
{asm("nop");}
}


void delay_loop1(unsigned long us)
{for(;us>0;us--)
{asm("nop");}
}

void init(void)
{DDRB= 0xFF;
ADCSRA= 0x00; // disable ADC
ACSR= 0x81; // Anlog comparator disable
//wdt_disable();
//DIDR0= 0x3F; // Digital input register enable
data[0]=0xFF;
data[2]=0xFF;
counter=0; // initial value
}

void data_send(void)
{for(i=0;i<24;i++)
{ wdt_disable();
if(data[counter/8] & (01<<(counter%8)))
{ PORTA= 0X40;
delay_loop1(220);
PORTA = 0X00;
delay_loop1(220);}
else{//PORTA= 0X00;
delay_loop1(220);
//PORTA= 0X40;
delay_loop1(220);}
counter++;}
}



void main(void)

{
init();
WDTCR=0x0F; //enable watchdog timer and set to 1.8 seconds
while (1)
{
asm volatile("STS reset_no,R16");
asm volatile("INC R16");
if(reset_no==15)
{
WDTCR=0x08;
WDTCR=0x00;
goto noteq; }
else
{ADCSRA= 0x00; // disable ADC
//WDTCR= 0xF; // WDT enable;reset; 8s;
MCUCR= 0x31; // power down mode
//sleep_mode();
}
}
{
noteq:asm volatile("CLR R16");
PORTB = 0X20; // enable temp sensor
delay_loop(30);
ADMUX= 0xE6; // Vref (1.1v) , channel pB3
ADCSRA= 0xEF; // enable ADC ; start conv.
sei(); // interrupt enable
WDTCR= 0x00; // WDT enable;reset;
MCUCR= 0x21; // sleep enable ;idle mode
sleep_mode();
//while (1);
}
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…