Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Declartion of header file

Status
Not open for further replies.

kaleem

New Member
Hi,

i have an error in the code.Actually i am using Atmel tiny 13 micro conttroller and i am defining DIDR register which stands for Digital input direction register.When i am compiling its showing error as DiDR undeclared.so please help me with the header file or declaration of this register.
Thank you.
 
I just programmed my first microcontroller, a attiny13, a couple of days ago. I still have much to learn, but spent the last two days studying the data sheet, and the tn13def file. Don't recall any DIDR. There is a DDR (Data Direction Register), where you set the pins for input or output.

Got me curious, and picked up the printout on tn13def.inc... There is a DIDR0, maybe you forgot the zero on the end. Oh, you never mentioned if you are using assembler or something else, not sure it matters.

Can you post the program? I just started myself, so examples are very useful learning tools. My big problem is setting up the Timer0 as a frequency generator, need a 38kHz output to one of the pins.
 
Convention is to use "DDRA" for the direction bits of port A, (also "PORTA" and "PINA" for the outputs and inputs).

These really ought to be already defined in the ".inc" files - if you downloaded the Atmel tools, look for a directory called "Appnotes" . Just copy the file into your project directory and throw in the include directive

.include "tn13def.inc"

and all the important bits should get defined...
 
Code

Hello my friend this is the code

#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/sfr_defs.h>
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 t,s;
unsigned char timecount = 0;
unsigned char reset_no;
/* ADC interrupt service routine*/
SIGNAL(SIG_ADC)
{ data[1] =ADCH; // read MSB into variable
PORTB = 0X00; // disable temp sensor
data_send(); // send packet data
ADCSRA= 0x00; // disable ADC
WDTCR= 0x29; // WDT enable;reset mode;
MCUCR= 0x70; // enable power down sleep ;
sleep_mode() ;
}
void main(void)

{
init();
asm volatile("STS reset_no,R22");
asm volatile("INC R22");
if(reset_no==37)
{goto noteq; }
else
{ADCSRA= 0x00; // disable ADC
WDTCR= 0x29; // WDT enable;reset; 8s;
MCUCR= 0x70; // power down mode
sleep_mode();
}
noteq:asm volatile("CLR R22");
PORTB = 0X20; // enable temp sensor
delay_loop(30);
ADMUX= 0x63; // Vref (1.1v) , channel pB3
ADCSRA= 0xC9; // enable ADC ; start conv.
sei(); // interrupt enable
WDTCR= 0x61; // WDT enable;reset;
MCUCR= 0x60; // sleep enable ;idle mode
sleep_mode();
SIGNAL(SIG_ADC)
while (1);
}
void data_send(void)
{for(i=0;i<24;i++)
{ wdt_disable();
if(data[counter/8] & (01<<(counter%8)))
{ PORTB= 0X04;
delay_loop(16);
PORTB = 0X00;
delay_loop(5);}
else{PORTB= 0X00;
delay_loop(16);
PORTB= 0X04;
delay_loop(5);}
counter++;}
}
void delay_loop(unsigned char us)
{for(;us>0;us--)
{asm("nop");}
}
void init(void) n
{DDRB= 0x35;
ADCSRA= 0x00; // disable ADC
ACSR= 0x81; // Anlog comparator disable
wdt_disable();
//DIDR0= 0x3F; // Digital input register disable
data[0]=0xFF;
data[2]=0xFF;
counter=0; // initial value
}
 
Avr

Thank you very much Harvey, I could clear the error.when i am simulating my program in AVR Studio,the whole program is not executing, I mean the initialization loop is repeating.please help me with this.

Thank you.
 
That's about all I had. Just started myself, but I'm doing it in assembler. I never actually programmed in 'C', but did try to learn it once. It was a little too structured and unforgiving for my previously bad programming habits. I did well with assembler on a 6502, the Tiny13 is only a little different. Kind of surprising how quickly I got back into the programming, been many years (15?).

Only had a couple of compile errors, and they were typos. Haven't figured out how to trigger an input yet in the simulator. Don't think there is a key press type trigger. Did find something about building a 'Stimuli log file', but it defines a stimulus (pin trigger) by clock cycles. Not sure how useful or how to use just yet. I know you are using the ADC, so you might need some sort of input.

Hope you get it figured put, let me know how it goes.
 
Two things:
1) You need to show us how you are compiling this program. This looks a lot like GCC, and if you are compiling you need to supply a flag that looks like "-mmcu=attiny13" or something

2) You need to find a book on C and read it - there are so many wrong things in the code that I'll be surprised if it does anything consistently... Find the "avr libc" manual and read through it - simple stuff like delay loops are already defined for you.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top