7 SEGMENT Interface With PIC18f4520
Program:
//Author : Palak Patel(M.Tech)
//Contact No:9173211683
//Title:7seg
//Platform: PIC18f4520
//Software:MPLAB
#include<p18f4520.h>
#define seg PORTC
#define control PORTD
void Delay_ms(unsigned int);
void display(unsigned char);
void main()
{
unsigned int i;
unsigned char a,b,c,d,j;
TRISC=0x00;
TRISD=0x00;
PORTD=0x00;
while(1)
{
for(i=0;i<1000;i++)
{
a=i;
b=a%10;
a=a/10;
c=a%10;
d=a/10;
for(j=0;j<10;j++)
{
control=0x06;
display(b);
Delay_ms(10);
control=0x05;
display(c);
Delay_ms(15);
control=0x03;
display(d);
Delay_ms(15);
}
}
}
}
void display(unsigned char n)
{
switch(n)
{
case 0:
seg=0xFC;
break;
case 1:
seg=0x60;
break;
case 2:
seg=0xDA;
break;
case 3:
seg=0xF2;
break;
case 4:
seg=0x66;
break;
case 5:
seg=0xB6;
break;
case 6:
seg=0xBE;
break;
case 7:
seg=0xE0;
break;
case 8:
seg=0xFE;
break;
case 9:
seg=0xF6;
break;
default:
seg=0x00;
break;
}
}
void Delay_ms(unsigned int p)
{
unsigned int i,j;
for(i=0;i<p;i++)
{
for(j=0;j<150;j++);
}
}
Simulation:
For Basic Electronics Kindally follow this Link:
http://basicelectonicspalakpatel.blogspot.in/2014/08/the-mosfet-as-switch.html
Program:
//Author : Palak Patel(M.Tech)
//Contact No:9173211683
//Title:7seg
//Platform: PIC18f4520
//Software:MPLAB
#include<p18f4520.h>
#define seg PORTC
#define control PORTD
void Delay_ms(unsigned int);
void display(unsigned char);
void main()
{
unsigned int i;
unsigned char a,b,c,d,j;
TRISC=0x00;
TRISD=0x00;
PORTD=0x00;
while(1)
{
for(i=0;i<1000;i++)
{
a=i;
b=a%10;
a=a/10;
c=a%10;
d=a/10;
for(j=0;j<10;j++)
{
control=0x06;
display(b);
Delay_ms(10);
control=0x05;
display(c);
Delay_ms(15);
control=0x03;
display(d);
Delay_ms(15);
}
}
}
}
void display(unsigned char n)
{
switch(n)
{
case 0:
seg=0xFC;
break;
case 1:
seg=0x60;
break;
case 2:
seg=0xDA;
break;
case 3:
seg=0xF2;
break;
case 4:
seg=0x66;
break;
case 5:
seg=0xB6;
break;
case 6:
seg=0xBE;
break;
case 7:
seg=0xE0;
break;
case 8:
seg=0xFE;
break;
case 9:
seg=0xF6;
break;
default:
seg=0x00;
break;
}
}
void Delay_ms(unsigned int p)
{
unsigned int i,j;
for(i=0;i<p;i++)
{
for(j=0;j<150;j++);
}
}
Simulation:
For Basic Electronics Kindally follow this Link:
http://basicelectonicspalakpatel.blogspot.in/2014/08/the-mosfet-as-switch.html
No comments:
Post a Comment