单片机C语言程序举例(二)
#include
#include
#include
unsigned int hour,minute,second,count;
sbit RS = P2^4;//Pin4
sbit RW = P2^5; //Pin5
sbit E
sbit BLCtrl = P2^7;
sbit KEY = P3^2;
#define Data
char data TimeNum[]="
char data Test1[]="
void DelayUs(unsigned char us)//delay us
{
}
void DelayMs(unsigned char ms)//delay Ms
{
}
void WriteCommand(unsigned char c)
{
}
void WriteData(unsigned char c)
{
}
void ShowChar(unsigned char pos,unsigned char c)
{
}
void ShowString (unsigned char line,char *ptr)
{
}
void InitLcd()
{
}
/////////////////////////////////////////////////////////////////
void main(void)
{
InitLcd();//初始化液晶
DelayMs(15);
sprintf(Test1," www.haotun.com ");//第一行
ShowString(0,Test1);
sprintf(TimeNum,"LCM1602 Test ok!");//第二行
ShowString(1,TimeNum);
while(1){
if(!KEY)
}
}
9.步进电机控制
#include
unsigned char code F_Rotation[4]={0x02,0x04,0x08,0x10};//正转表格
unsigned char code B_Rotation[4]={0x10,0x08,0x040,0x02};//反转表格
void Delay(unsigned int i)//延时
{
}
main()
{
}
10. 直流电机调速
#include
sbit KEY1 = P3^1;
sbit PWM = P1^5;
unsigned char CYCLE; //定义周期 该数字X基准定时时间 如果是10 则周期是10 x 0.1ms
unsigned char PWM_ON ;//定义高电平时间
void delay(unsigned int cnt)
{
}
main()
{
unsigned char PWM_Num;//定义档位
TMOD |=0x01;//定时器设置 1ms in 12M crystal
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;//定时1mS
IE= 0x82;
TR0=1;
CYCLE = 10;// 时间可以调整 这个是10步调整 周期10ms 8位PWM就是256步
while(1)
if(!KEY1)
}
void tim(void) interrupt 1 using 1
{
static unsigned char count; //
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;//定时1mS
if (count==PWM_ON)
if(count == CYCLE)
}
11.秒表
#include
code unsigned char tab[]=
unsigned char Dis_Shiwei;//定义十位
unsigned char Dis_Gewei; //定义个位
unsigned char S_Dis_Shiwei;//定义秒十位
unsigned char S_Dis_Gewei; //定义秒个位
unsigned char second,msecond;
void CLR(void);
void delay(unsigned int cnt)
{
}
main()
{
EX0=1;//外部中断0设置
IT0=1;
EX1=1;//外部中断1设置
IT1=1;
TMOD |=0x01;//定时器设置 10ms in 12M crystal
TH0=0xd8;
TL0=0xf0;
ET0=1;
TR0=0;
EA=1;
CLR();
while(1)
}
void tim(void) interrupt 1 using 1
{
单片机C语言程序举 相关文章:
- 单片机C语言程序举例(一)(11-22)
- 单片机C语言程序举例(三)(11-22)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)