首页 > > 详细

代作LED指示灯编程、讲解LED、辅导C报告 解析C/C++编程|解析Haskell程序

#include
#include
#include
#include "1602.h"
#include "delay.h"
sbit Key1 = P3^5;
sbit Key2 = P3^3;
sbit Key3 = P1^3;
sbit Led = P3^6; //LED
sbit Speak = P2^2;
unsigned int count;
unsigned char Flag;
unsigned char full;
int Angle_up=90; //??????
int Angle_down=20; //??????
int max,min;
unsigned int mb=45,counter,n;
unsigned int Oldcount,Newcount; ///
unsigned char Sycount; //
void KeyScan(void) //
{
unsigned char temp[3];//
if(Key1 == 0) //
{
DelayMs(10); //
if(Key1 == 0)
{
Flag=1;
count++;
if(count==1)
{
LCD_Clear();
LCD_Write_Com(0x0c); //
temp[0]=Angle_up/100+'0';
temp[1]=Angle_up%100/10+'0';
temp[2]=Angle_up%10+'0';
LCD_Write_String(0,0,"Value_up :");
LCD_Write_String(13,0,temp);
temp[0]=Angle_down/100+'0';
temp[1]=Angle_down%100/10+'0';
temp[2]=Angle_down%10+'0';
LCD_Write_String(0,1,"Value_down: ");
LCD_Write_String(13,1,temp);
}
if(count>2)
{
LCD_Write_Com(0x0c);//
count=0;
Flag=0;
LCD_Clear();
LCD_Write_String(0,0,"Speed: d/min");
LCD_Write_String(0,1,"Level: ");
}
}
while(Key1 == 0);//
}
}
void Set_angle(unsigned char sel)
{
unsigned char temp[3];
max=360;
min=0;
if(sel==2) {max=200;min=0;LCD_cursor(15,1);} //angle_down
if(sel==1) {max=200;min=0;LCD_cursor(15,0);} //angle_up
if(Key3 == 0)
{
DelayMs(10);
if(Key3 == 0)
{
if(sel==1) //
{
Angle_up++;
if(Angle_up>max) Angle_up=min;//
if(Angle_up LCD_Write_Com(0x0c); //,
temp[0]=Angle_up/100+'0';
temp[1]=Angle_up%100/10+'0';
temp[2]=Angle_up%10+'0';
LCD_Write_String(13,0,temp);
}
if(sel==2) //
{
Angle_down++;
if(Angle_down>max) Angle_down=min;//
if(Angle_down LCD_Write_Com(0x0c); //,
temp[0]=Angle_down/100+'0';
temp[1]=Angle_down%100/10+'0';
temp[2]=Angle_down%10+'0';
LCD_Write_String(13,1,temp);
}
}
while(Key3 == 0);//
}
if(Key2 == 0)
{
DelayMs(10);
if(Key2 == 0)
{
if(sel==1) //
{
Angle_up--;
if(Angle_up>max) Angle_up=min;//
if(Angle_up LCD_Write_Com(0x0c); //,
temp[0]=Angle_up/100+'0';
temp[1]=Angle_up%100/10+'0';
temp[2]=Angle_up%10+'0';
LCD_Write_String(13,0,temp);
}
if(sel==2) //
{
Angle_down--;
if(Angle_down>max) Angle_down=min;//
if(Angle_down LCD_Write_Com(0x0c); //,
temp[0]=Angle_down/100+'0';
temp[1]=Angle_down%100/10+'0';
temp[2]=Angle_down%10+'0';
LCD_Write_String(13,1,temp);
}
}
while(Key2 == 0);//
}
}
void Init(void)
{
//0
TMOD |= 0x01; //T01
TH0 = 0x4C;
TL0 = 0x00; //T050ms
TR0 = 1; //T0
ET0 = 1; //
//0
IT0 = 0; //0
EX0 = 1;//

EA = 1; //
}
void main(void)
{
LCD_Init();
LCD_Clear();
Init();
LCD_Write_String(0,0,"Speed: d/min");
while(1)
{
KeyScan();
if(Flag==0)
{
//
LCD_Write_Char(7,0,mb/100+0x30);
LCD_Write_Char(8,0,mb%100/10+0x30);
LCD_Write_Char(9,0,mb%10+0x30);
//
LCD_Write_Char(14,1,full+0x30);
if((mb>Angle_down&&mb {
Speak=1;
}
else
{
Speak=0;
}
}
else
{
Speak=1;
Set_angle(count);
}
}
}
//**************************************************
//:30s*2
void External0() interrupt 0//0
{

counter++;
}
//***************************************************
//
//30s
void Timer0() interrupt 1
{
TH0 = 0x4C;
TL0 = 0x00;
n++;

if(n==600) //30s
{
mb=2*counter; //
n=0; //,
counter=0;
}
}

#include "1602.h"
#include "delay.h"

sbit RS = P2^7; //
sbit RW = P2^6;
sbit EN = P2^5;

#define RS_CLR RS=0
#define RS_SET RS=1

#define RW_CLR RW=0
#define RW_SET RW=1

#define EN_CLR EN=0
#define EN_SET EN=1

#define DataPort P0


/**/
void delay1(int i)
{
int j,k;
for(j=0;j for(k=0;k<10;k++);
}
/*------------------------------------------------

------------------------------------------------*/
void LCD_Check_Busy(void)
{
unsigned char temp=0;
DataPort= 0xFF;
RS_CLR;
RW_SET;
if(P0^7==1)
{
EN_SET;
EN_CLR;
}
}
/*------------------------------------------------

------------------------------------------------*/
void LCD_Write_Com(unsigned char com)
{
LCD_Check_Busy();
RS_CLR;
delay1(10);
RW_CLR;
delay1(10);
DataPort= com;
delay1(10);
EN_SET;
delay1(10);
EN_CLR;
}
/*------------------------------------------------

------------------------------------------------*/
void LCD_Write_Data(unsigned char Data)
{
LCD_Check_Busy();
RS_SET;
delay1(10);
RW_CLR;
delay1(10);
DataPort= Data;
EN_SET;
delay1(10);
EN_CLR;
}
/*------------------------------------------------

------------------------------------------------*/
void LCD_Clear(void)
{
LCD_Write_Com(0x01);
DelayMs(5);
}
/*------------------------------------------------

------------------------------------------------*/
void LCD_Write_String(unsigned char x,unsigned char y,unsigned char *s)
{
if (y == 0)
{
LCD_Write_Com(0x80 + x); //
}
else
{
LCD_Write_Com(0xC0 + x); //
}
while (*s)
{
LCD_Write_Data( *s);
s ++;
}
}
/*------------------------------------------------

------------------------------------------------*/
void LCD_Write_Char(unsigned char x,unsigned char y,unsigned char Data)
{
if (y == 0)
{
LCD_Write_Com(0x80 + x);
}
else
{
LCD_Write_Com(0xC0 + x);
}
LCD_Write_Data( Data);
}
/*------------------------------------------------

------------------------------------------------*/
void LCD_Init(void)
{
LCD_Write_Com(0x38); /**/
DelayMs(5);
LCD_Write_Com(0x38);
DelayMs(5);
LCD_Write_Com(0x38);
DelayMs(5);
LCD_Write_Com(0x38);
LCD_Write_Com(0x08); /**/
LCD_Write_Com(0x01); /**/
LCD_Write_Com(0x06); /**/
DelayMs(5);
LCD_Write_Com(0x0C); /**/
}
void LCD_cursor(unsigned char X,unsigned char Y)
{
if (Y == 0)
{
LCD_Write_Com(0x80 + X);
}
else
{
LCD_Write_Com(0xC0 + X);
}
LCD_Write_Com(0x0e);
}


联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!