can anyone pls explain this program to me?its an emergency n this is very important for my final yr engnr project.I need the explaination by thursday.so pls help..
#include %26lt;pic.h%26gt;
#include %26lt;stdio.h%26gt;
#include %26lt;delay10.c%26gt;
static void interrupt IntRoutine();
void Send();
short int Flg=0;
int Cnt = 0,Oflow=0,Mytime=0,Adval,Hbc,Hbr;
char St1[4],St2[4],St4[3];
void main()
{
TRISB = 0x00;
PORTB = 0x00;
TRISD = 0x00;
PORTD = 0x00;
TRISE = 0x00;
TRISC = 0xbf;
ADCON0 = 0x81;
ADCON1 = 0x82;
SPBRG = 64;
TXEN = 1;
SYNC = 0;
BRGH = 1;
SPEN = 1;
CREN = 1;
DelayMs(200);
DelayMs(200);
DelayMs(200);
DelayMs(200);
DelayMs(200);
LCD_SendCmd(0x01);
LCD_SendCmd(0x80);
LCD_puts("Ebc:");
LCD_SendCmd(0x88);
LCD_puts("Tim:");
LCD_SendCmd(0xc3);
LCD_puts("Ebr: Bpm");
T1CON = 0x00; // Enable Timer1
PEIE = 1;
GIE = 1;
TMR1IF = 0;
TMR1IE = 1;
TMR1L = 0xaf;
TMR1H = 0x3c;
TMR1ON = 1;
for(;;)
{
if(Oflow)
{
Oflow = 0;
Mytime++;
}
ADCON0 = 0x81;
DelayUs(50);
ADGO = 1;
while(ADGO) continue;
Adval = (ADRESH * 256) + ADRESL;
if(Adval %26lt; 100 %26amp;%26amp; Flg == 0)
{
Hbc++;
Flg = 1;
}
if(Adval %26gt; 100 %26amp;%26amp; Flg == 1)
{
Flg = 0;
}
if(Mytime %26gt; 3 %26amp;%26amp; Mytime %26lt; 60) RD0 = 0;
if(Mytime %26gt;= 60)
{
Mytime = 0;
Ebr = Ebc;
if(Ebc %26gt; 15)
{
RD0 = 1;
}
Ebc = 0;
}
sprintf(St1,"%3d",Ebc);
LCD_SendCmd(0x84);
LCD_puts(St1);
sprintf(St2,"%3d",Ebr);
LCD_SendCmd(0xc8);
LCD_puts(St2);
sprintf(St4,"%02d",Mytime);
LCD_SendCmd(0x8c);
LCD_puts(St4);
Send();
DelayMs(2);
}
}
static void interrupt IntRoutine()
{
if(TMR1IF)
{
TMR1IF = 0;
Cnt++;
if(Cnt %26gt;= 50)
{
Cnt = 0;
Oflow = 1;
}
TMR1ON = 0;
TMR1L = 0xaf;
TMR1H = 0x3c;
TMR1ON = 1;
}
}
Can someone help me with my pic microcontroller project???
Do I earn your degree, if I answer your question? Please post your degree on your 360 page, so I can conveniently download it.
Thanks
Reply:well, theres a lot missing, but these lines are setting up the micro.
TRISB = 0x00;
PORTB = 0x00;
TRISD = 0x00;
PORTD = 0x00;
TRISE = 0x00;
TRISC = 0xbf;
ADCON0 = 0x81;
ADCON1 = 0x82;
SPBRG = 64;
TXEN = 1;
SYNC = 0;
BRGH = 1;
SPEN = 1;
CREN = 1;
this is initializing an LCD display after some delay time, and setting up the timer interrupt.
DelayMs(200);
DelayMs(200);
DelayMs(200);
DelayMs(200);
DelayMs(200);
LCD_SendCmd(0x01);
LCD_SendCmd(0x80);
LCD_puts("Ebc:");
LCD_SendCmd(0x88);
LCD_puts("Tim:");
LCD_SendCmd(0xc3);
LCD_puts("Ebr: Bpm");
this is setting up a timer interrupt
T1CON = 0x00; // Enable Timer1
PEIE = 1;
GIE = 1;
TMR1IF = 0;
TMR1IE = 1;
TMR1L = 0xaf;
TMR1H = 0x3c;
TMR1ON = 1;
this is the timer interrupt, just setting Oflow to 1 when it reaches a certain time
static void interrupt IntRoutine()
{
if(TMR1IF)
{
TMR1IF = 0;
Cnt++;
if(Cnt %26gt;= 50)
{
Cnt = 0;
Oflow = 1;
}
TMR1ON = 0;
TMR1L = 0xaf;
TMR1H = 0x3c;
TMR1ON = 1;
}
}
this is a never ending loop, and it looks like it is reading in an A/D converter every Mytime amount of time and probably displaying the results on the LCD. its hard to tell without the rest of the code though.
for(;;)
{
if(Oflow)
{
Oflow = 0;
Mytime++;
}
ADCON0 = 0x81;
DelayUs(50);
ADGO = 1;
while(ADGO) continue;
Adval = (ADRESH * 256) + ADRESL;
if(Adval %26lt; 100 %26amp;%26amp; Flg == 0)
{
Hbc++;
Flg = 1;
}
if(Adval %26gt; 100 %26amp;%26amp; Flg == 1)
{
Flg = 0;
}
if(Mytime %26gt; 3 %26amp;%26amp; Mytime %26lt; 60) RD0 = 0;
if(Mytime %26gt;= 60)
{
Mytime = 0;
Ebr = Ebc;
if(Ebc %26gt; 15)
{
RD0 = 1;
}
Ebc = 0;
}
sprintf(St1,"%3d",Ebc);
LCD_SendCmd(0x84);
LCD_puts(St1);
sprintf(St2,"%3d",Ebr);
LCD_SendCmd(0xc8);
LCD_puts(St2);
sprintf(St4,"%02d",Mytime);
LCD_SendCmd(0x8c);
LCD_puts(St4);
Send();
DelayMs(2);
}
}
Reply:We can help you
contact us at expert.myitcareer .org
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment