0% found this document useful (0 votes)
13 views

Mclab

Uploaded by

avimane0510
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Mclab

Uploaded by

avimane0510
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Embedded C Programming for generating delay using Timer 0

#include<p18f4550.h>
void delay();
void main()
{
TRISD=0x00;
while(1)
{
PORTD=0xFF;
delay();
PORTD=0x00;
delay();
}
}
void delay()
{
T0CON=0x08;
TMR0H=0x3C;
TMR0L=0xB0;
TMR0ON=1;
while(INTCONbits.TMR0IF==0);
TMR0ON=0;
INTCONbits.TMR0IF=0;
}
LED FLASHING
#include<p18f4550.h>
void delay()
{
int i;
for(i=1;i<10000;i++)
{}
}
void main()
{
TRISD=0x00;
while(1)
{
PORTD=0xff;
delay();
PORTD=0x00;
delay();
}
}
BITWISE ORRING LED FLASHER
#include<p18f4550.h>
void delay()
{int i;
for(i=0;i<6000;i++)
{}
}
void main()
(
int a,b,c,i;
TRISD=0x00;
while(1)
{ a=0x80;
b=0x01;
for(i=1;i<=4;i++)
{ c=a|b;
PORTD=c;
delay();
a=a>>1;
b=b<<1;
}
}
}
LED RUNNING LIGHT FLASHING
#include<p18f4550.h>
void delay()
{
int i;
for(i=1;i<5000;i++);
}
void main()
{
unsigned char a=0x01;
int j;
TRISD=0x00;
while(1)
{
a=0x01;
for(j=0;j<=8;j++)
{
PORTD=a;
delay();
a=a<<1;
}
}
}

You might also like