Jump to content
ELFORUM - Forumul electronistilor

atmega 16 timer + watchdog

Guest Kh30pS

Recommended Posts

Guest Kh30pS

Salutare, sunt nou pe acest forum si precizez ca sunt foarte incepator in programarea embeded.


Am de rezolvat o problema care suna cam asa


" Calculati si transmiteti pe seriala in formatul XXX.X ms valoarea tipica a WD-timerului in cazul utilizarii prescalarului WDP2-0 = 010;"


O sa postez partea de cod care o am. Nu imi dau seama ce este gresit. Transmitarea pe seriala este in alt format, dar o pot modifica eu. As dori sa stiu daca ma poate ajuta cineva.



#include <inavr.h>#include <iom16.h>#include "usart.h"__no_init long x;void main(void){    unsigned char c[]={'x','.','x','x','x',' ','u','s'};    unsigned char i;                    float t;    USART_initialize(BAUD_RATE);     if(MCUCSR&0x08==0x00)    {	x=0;       }    TCCR1B|=0x02;//configurez timer1 cu prescalare de 8   // TCCR1B|= (1<<CS11);    WDTCR|=(1<<WDP1);//setez prescaler wd    TCNT1=0;  //reset timer1    WDTCR|=(1<<WDE);//enable wd    x=x*8;//calculez in cat timp s-a resetat (in us)    t=(float)x/65536;//vad cat dureaza un ciclu al wd    x=t*1000;    c[0]=(x/1000)+'0';    for(i=4;i>1;i--)    {              c[i]=(x%10)+'0';              x=x/10;           }    for( i=0;i<8;i++){        USART_transmit(c[i]);      }    USART_transmit(0x0d);////////////////////////////////////////while (1)      {                       	x=TCNT1;      }}
Link to comment
  • Replies 0
  • Created
  • Last Reply

Popular Days

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines