Beruflich Dokumente
Kultur Dokumente
1 of 11
http://www.embed4u.com/8051-pwm-c-program/
Embed4u
All About Embedded Hardware and Software
Home
Code Library
DOWNLOAD
Drivers
Electronics
Projects
Related Videos
Schematics
Technology
Tutorial
Ads by Google
PWM
Timer
Timer Circuit
#include<reg51.h>
sbit x=P1^1;
void scan_col();
void scan_row();
void init_timer();
void runtimer();
5/23/2012 3:50 PM
2 of 11
http://www.embed4u.com/8051-pwm-c-program/
void pwn_generator();
void toggle();
void delay();
void busy_check();
void init_lcd();
void display();
void ton_array();
void toff_array();
void init_array();
char a[4][3];
int ton[4][3];
int toff[4][3];
int i = 0,r,c;
xdata char *ptr=(xdata char*)0xfffc;
void init_array()
{
a[0][0]=1;
a[0][1]=2;
a[0][2]=3;
a[1][0]=4;
a[1][1]=5;
a[1][2]=6;
a[2][0]=7;
a[2][1]=8;
a[2][2]=9;
a[3][0]=*';
a[3][1]=0;
5/23/2012 3:50 PM
3 of 11
http://www.embed4u.com/8051-pwm-c-program/
a[3][2]=#';
void display()
{
init_lcd();
*(ptr+1)=001;
*(ptr) = a[r];
busy_check();
}
void init_lcd()
{
*(ptr+1)=000;
*(ptr)=038;
busy_check();
*(ptr+1)=000;
*(ptr)=00e;
busy_check();
*(ptr+1)=000;
*(ptr)=080;
busy_check();
*(ptr+1)=000;
*(ptr)=001;
busy_check();
}
void busy_check()
{
5/23/2012 3:50 PM
4 of 11
http://www.embed4u.com/8051-pwm-c-program/
*(ptr+1)=002;
while((*ptr&080)!=000);
}
void delay()
{
i=30000;
while(i);
}
5/23/2012 3:50 PM
5 of 11
http://www.embed4u.com/8051-pwm-c-program/
toff[0][1]=090;
toff[0][2]=0xa0;
toff[1][0]=0xb0;
toff[1][1]=0xc0;
toff[1][2]=0xd0;
toff[2][0]=0xe0;
toff[2][1]=000;
toff[2][2]=0xff;
toff[3][0]=0xff;
toff[3][1]=0xff;
toff[3][2]=0xff;
}
void scan_col()
{
P2=0068;
while((P2&0068)==0068);
if((P2&060)==060)
{
c=0;
scan_row();
}
if((P2&048)==048)
{
c=1;
scan_row();
}
if((P2&028)==028)
{
5/23/2012 3:50 PM
6 of 11
http://www.embed4u.com/8051-pwm-c-program/
c=2;
scan_row();
}
}
void scan_row()
{
P2=096;
while((P2&096)==096);
if((P2&086)==086)
{
r=0;
display();
pwn_generator();
}
if((P2&092)==092)
{
r=1;
display();
pwn_generator();
}
if((P2&094)==094)
{
r=2;
display();
pwn_generator();
}
if((P2&016)==016)
{
5/23/2012 3:50 PM
7 of 11
http://www.embed4u.com/8051-pwm-c-program/
r=3;
display();
pwn_generator();
}
}
void pwn_generator()
{
TR0 = 0;
if (r != 2 && c != 1)
{
TH0 = ton[r];
}
else
{
TH0 = 0xfe;
}
x = 1;
TL0=000;
TR0 = 1;
}
5/23/2012 3:50 PM
8 of 11
http://www.embed4u.com/8051-pwm-c-program/
{
TH0 = toff[r];
TL0 = 000;
}
else
{
TH0 = ton[r];
TL0 = 000;
}
TR0 = 1;
}
void toggle()
{
x = ~x;
}
void init_timer()
{
main()
5/23/2012 3:50 PM
9 of 11
http://www.embed4u.com/8051-pwm-c-program/
{
x = 000;
init_lcd();
init_array();
init_timer();
ton_array();
toff_array();
while(1)
{
scan_col();
delay();
}
}
Related posts:
1.
2.
3.
4.
5.
Categories: Code Library Tags: 8051 c code for pwm, 8051 PWM C Program|embed4u.com, Pulse Width
Modulation (PWM) tutorials: : 8051 Microcontroller ..., pwm c program for microcontroller|embed4u.com, pwm
using 805, using micro pwm to generate pure sine wave
Comments (0) Trackbacks (0) Leave a comment Trackback
5/23/2012 3:50 PM
10 of 11
http://www.embed4u.com/8051-pwm-c-program/
1. No comments yet.
1. No trackbacks yet.
You must be logged in to post a comment.
8051 External Interrupt c program: 8051 serial program
RSS
Recent Posts
stepper motor driver circuit using microcontroller
5/23/2012 3:50 PM
11 of 11
http://www.embed4u.com/8051-pwm-c-program/
Categories
Code Library
DOWNLOAD
Drivers
Electronics
Projects
Related Videos
Schematics
Technology
Tutorial
Blogroll
HEXsource Technologies
Pages
About Us
Contact us
Privacy Policy
Top
Copyright 2009-2011 Embed4u
5/23/2012 3:50 PM