8.液晶背光操控
#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
{
TH0=0xd8;//从头赋值
TL0=0xf0;
msecond++;
if (msecond==100)
}
void ISR_INT0(void) interrupt 0 using 1
{
}
void ISR_INT1(void) interrupt 2 using 1
{
if(TR0==0)//中止时才能够清零
}
void CLR(void)
{
}
12.把戏灯
#include
unsigned char code seg[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,0xff,0x00,0,0×55,0x55,0xaa,0xaa};//rom答应状况能够无限增加
////////////////////////////////////////////////////////
void delay(unsigned int cnt)//简易延时
{
}
///////////////////////////////////////////////////////
main()
{
////////////////////////////////////
}
13.红绿灯
#include
bit red,green,yellow,turnred;
code unsigned char tab[]=
unsigned char Dis_Shiwei;//界说十位
unsigned char Dis_Gewei; //界说个位
void delay(unsigned int cnt)
{
}
main()
{
TMOD |=0x01;//守时器设置 10ms in 12M crystal
TH0=0xd8;
TL0=0xf0;
IE= 0x82;
TR0=1;
P1=0xfc;//红灯亮
red =1;
while(1)
}
void tim(void) interrupt 1 using 1
{
static unsigned char second=60,count; //初值99
TH0=0xd8;//从头赋值
TL0=0xf0;
count++;
if (count==100)
}