📄 lcd1.c
字号:
#include<reg52.h>
#include<absacc.h>
sbit RS=P2^0;
sbit RW=P2^1;
sbit EN=P2^2;
sbit clock=P2^7;
sbit cc=P1^0;
sbit cc1=P2^6;
sbit high=P3^2;
sbit low=P3^3;
unsigned char Counter=1;Flag1=0;Flag2=0;ccFlag=1;
unsigned int Timerlow;Timerhigh;Counter1=100;
void delay(unsigned long delay_count)
{
while(delay_count--);
}
void enable(char c)
{
unsigned char temp;
do
{
RS=0;RW=1;EN=1;
temp=P0;
temp&=0x80;
EN=0;
}while(temp);
P0=c;
RS=0;RW=0;EN=1;
delay(20);
EN=0;
}
void WriteCharToLCD(unsigned char c2)
{
unsigned char temp;
do
{
RS=0;RW=1;EN=1;
temp=P0;
temp&=0x80;
EN=0;
}while(temp);
if(c2==0x0D)return;
P0=c2;
RS=1;RW=0;EN=1;
EN=0;
delay(300);
}
void InitialLCD(void)
{
enable(0x01);delay(200);
enable(0x38);
enable(0x0c);
enable(0x14);
delay(2000);
}
void ClearLCD(void)
{
enable(0x01);
delay(200);
enable(0x0c);
}
void WriteStrToLCD(unsigned char row,unsigned char col,unsigned char *c)
{
unsigned char count=0,tempAC;
switch(col)
{
case 1:enable(0x80+row-1);break;
case 2:enable(0xC0+row-1);break;
default:
break;
}
count=0;
while(*c!=0)
{
delay(20);
WriteCharToLCD(*c);
c++;
P0=0xFF;
delay(100);
RS=0;RW=1;EN=1;
tempAC=P0;
EN=0;
tempAC&=0x7F;
if(tempAC==0x14)
enable(0x80+0x40);
if(tempAC==0x54)
enable(0x80+0x14);
if(tempAC==0x40)
enable(0x80+0x54);
}
}
/*
void InitialTC(void)
{
TMOD=0x1F;
TH1=0x0;TL1=0x68; //T1=1000;
EA=1;
ET1=1;
TR1=1;
EX0=1;EX1=1;
TF1=0;
IE0=0;
IE1=0;
}
void InterruptEX0 (void) interrupt 0
{
if(Counter<=3)
{
++Counter;
}
}
void InterruptEX1 (void) interrupt 2
{
if(Counter>=1)
{
--Counter;
}
}
/*void InterruptT1 (void) interrupt 3
{
clock=(~clock);
switch(Counter)
{
case 1: Timerhigh=0x27;Timerlow=0x10; //T1=10000,--100Hz
case 2: Timerhigh=0x13;Timerlow=0x88; //T1=5000,--200Hz
case 3: Timerhigh=0x07;Timerlow=0xD0; //T1=2000,--500Hz
case 4: Timerhigh=0x03;Timerlow=0xE8; //T1=1000,--1000Hz
default: Timerhigh=0x03;Timerlow=0xE8;
break;
}
TH1=Timerhigh;TL0=Timerlow;
} */
void main(void)
{
// InitialTC();
InitialLCD();
delay(100);
ClearLCD();
delay(100);
WriteStrToLCD(1,1," Motor Driver");
WriteStrToLCD(1,2,"Design by:IC lab");
delay(20000);
WriteStrToLCD(1,2," Speed:high ");
P2=(P2|0x0F8);
while(1)
{
/* switch(Counter)
{
case 1: Counter1=1000;WriteStrToLCD(1,2,"Frequency:100 Hz"); //T1=10000,--100Hz
case 2: Counter1=500;WriteStrToLCD(1,2,"Frequency:200 Hz"); //T1=5000,--200Hz
case 3: Counter1=200;WriteStrToLCD(1,2,"Frequency:500 Hz"); //T1=2000,--500Hz
case 4: Counter1=100;WriteStrToLCD(1,2,"Frequency:1000Hz"); //T1=1000,--1000Hz
default:
break;
} */
if(high==0)
{
Counter1=100;
WriteStrToLCD(1,2," Speed: high ");
}
if(low==0)
{
Counter1=1000;
WriteStrToLCD(1,2," Speed: low ");
}
delay(Counter1);
clock=(~clock);
if(cc==0)
{
delay(50);
cc1=(~cc1);
delay(50);
ccFlag=1;
}
if(ccFlag==1)
{
ccFlag=0;
if(cc1==1)
{
WriteStrToLCD(1,1," direction: + ");
}
else
{
WriteStrToLCD(1,1," direction: - ");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -