📄 signal.c
字号:
#include <stdio.h> //0x30 ok;
#include <..\ATMEL\AT89X51.H> //0x80 right;
#include <stdlib.h> //0x70 down;
#include <intrins.h> //0x60 left;
#include <string.h> //0x20 up;
#include <math.h> //0x40 empty;
#include "output.h" //0x10 back;
////P1_1 中断显示信号 /////////////////////////////
////P2_7 信息载入指示灯 //////////////////////////
extern char code CharTable[128L*8L];
bit flag=0,lcdflag=0,right=0,left_right=0,runflag=0;
unsigned char key0,key,key1,key2,key3,key4,key5;
char buf[9]={1,2,3,4,5,6,7,8,9},*top,*bottom,lcdtemp=1,page=0,ww=1;
int count=0;
unsigned char sig=1,out=7;
unsigned long j;
void delay(long time)/////////int time////500//////
{
long i=time,j;
if(i==0){return;}
else
{
while(i)
{
j=5;
while(j){j--;}
i--;
}
}
}
unsigned char Square(unsigned char x)
{
unsigned char i,y=1;
for(i=1;i<=x;i++)
{y=y*2;}
return y;
}
void ok(unsigned char ok)
{ while(ok!=0)
{ok=ok-1;
P1_7=0;P1_6=1;P1_5=1;P1_4=0;delay(1500);
P1_7=1;P1_6=1;P1_5=1;P1_4=1;delay(70000);//ok
}
}
void okok(unsigned char ok)
{ while(ok!=0)
{ok=ok-1;
P1_7=0;P1_6=1;P1_5=1;P1_4=0;delay(1500);
P1_7=1;P1_6=1;P1_5=1;P1_4=1;delay(25000);//ok
}
}
void goup(unsigned char up)
{ while(up!=0)
{up=up-1;
P1_7=0;P1_6=0;P1_5=1;P1_4=0;delay(1500);
P1_7=1;P1_6=1;P1_5=1;P1_4=1;delay(25000);//up25000
}
}
void down(unsigned char down)
{ while(down!=0)
{down=down-1;
P1_7=0;P1_6=0;P1_5=1;P1_4=1;delay(1500);
P1_7=1;P1_6=1;P1_5=1;P1_4=1;delay(25000);//down25000
}
}
void back(unsigned char back)
{
while(back!=0)
{back=back-1;
P1_7=0;P1_6=1;P1_5=1;P1_4=1;delay(1500);
P1_7=1;P1_6=1;P1_5=1;P1_4=1;delay(25000);//back
}
}
void abc()
{
P1_7=0;P1_6=0;P1_5=0;P1_4=0;delay(1500);
P1_7=1;P1_6=1;P1_5=1;P1_4=1;delay(25000);//shezhi30000
delay(90000);
}
void goright(unsigned char right)
{
while(right!=0)
{right=right-1;
P1_7=0;P1_6=1;P1_5=0;P1_4=1;delay(1500);
P1_7=1;P1_6=1;P1_5=1;P1_4=1;delay(25000);//zhishi30000
}
}
void hello(unsigned char aa)
{
down(2);
okok(2);down(aa-1);okok(1);
}
unsigned char pre_Key_Scan()
{
unsigned char Key;
P2_5=0;
P2_6=1;
if (P2_4==0)
{ Key=0x30&0xf0; return Key;}
else if(P2_3==0)
{ Key=0x20&0xf0; return Key;}
else if(P2_2==0)
{ Key=0x10&0xf0; return Key;}
else if(P2_1==0)
{ Key=0x40&0xf0; return Key;}
P2_6=0;
P2_5=1;
if( P2_4== 0 )
{ Key=0x60&0xf0; return Key;}
else if (P2_3== 0 )
{ Key=0x70&0xf0; return Key;}
else if (P2_2== 0 )
{ Key=0x080&0xf0; return Key;}
else if (P2_1== 0 )
{ Key=0x40&0xf0; return Key;}
else {return 0;}
}
unsigned char Key_Scan()
{
unsigned char Key,prekey,prekey1;
P2_5=0;
P2_6=1;
if (P2_4==0)
{ Key=0x30; delay(10); prekey=pre_Key_Scan();delay(10);prekey1=pre_Key_Scan();delay(10);
if( (Key=prekey)&&(Key=prekey1) ){while(P2_4==0) ;} count=0;j=0;return Key&0xf0;}
else if(P2_3==0)
{ Key=0x20; delay(10); prekey=pre_Key_Scan();delay(10);prekey1=pre_Key_Scan();delay(10);
if( (Key=prekey)&&(Key=prekey1) ){while(P2_3==0);} count=0;j=0; return Key&0xf0;}
else if(P2_2==0)
{ Key=0x10;delay(10); prekey=pre_Key_Scan();delay(10);prekey1=pre_Key_Scan();delay(10);
if( (Key=prekey)&&(Key=prekey1) ){while(P2_2==0); }count=0;j=0; return Key&0xf0;}
else if(P2_1==0)
{ Key=0x40;delay(10); prekey=pre_Key_Scan();delay(10);prekey1=pre_Key_Scan();delay(10);
if( (Key=prekey)&&(Key=prekey1) ){while(P2_1==0);} count=0;j=0; return Key&0xf0;}
P2_6=0;
P2_5=1;
if( P2_4== 0 )
{ Key=0x60;delay(10); prekey=pre_Key_Scan();delay(10);prekey1=pre_Key_Scan();delay(10);
if( (Key=prekey)&&(Key=prekey1) ){ while(P2_4==0); }count=0;j=0; return Key&0xf0;}
else if (P2_3== 0 )
{ Key=0x70;delay(10); prekey=pre_Key_Scan();delay(10);prekey1=pre_Key_Scan();delay(10);
if( (Key=prekey)&&(Key=prekey1) ){while(P2_3==0); } count=0;j=0;return Key&0xf0;}
else if (P2_2== 0 )
{ Key=0x080;delay(10); prekey=pre_Key_Scan();delay(10);prekey1=pre_Key_Scan();delay(10);
if( (Key=prekey)&&(Key=prekey1) ){while(P2_2==0); } count=0;j=0;return Key&0xf0;}
else if (P2_1== 0 )
{ Key=0x40; delay(10); prekey=pre_Key_Scan();delay(10);prekey1=pre_Key_Scan();delay(10);
if( (Key=prekey)&&(Key=prekey1) ){while(P2_1==0);} count=0;j=0;return Key&0xf0;}
else {return 0;}
}
/*
LCDWriteCom1(unsigned char com)
{
bit flag;
A0 = 0;
RW=1;
do{
P0=0xff;
CS1=0;
flag=P0_7;
CS1=1;
}while(flag);
RW=0;
P0=com;
CS1=0;
CS1=1;
}
//向主LCD写数据 /
LCDWriteDat1(unsigned char dat)
{
bit flag;
A0 = 0;
RW=1;
do{
P0=0xff;
CS1=0;
flag=P0_7;
CS1=1;
}while(flag);
A0=1;
RW=0;
P0=dat;
CS1=0;
CS1=1;
}
unsigned char LCDReadDat1()
{
bit flag;
long i;
unsigned char dat;
A0 = 0;
RW=1;
do{
P0=0xff;
CS1=0;
flag=P0_7;
CS1=1;
i++;
}while(flag);
CS1=0;
A0=1;
RW=1;
dat=P0;
CS1=1;
RW=0;
P0=0xff;
RW=1;
CS1=0;
dat=P0;
CS1=1;
return dat;
}
//向从LCD写命令
LCDWriteCom2(unsigned char com)
{
bit flag;
A0 = 0;
RW=1;
do{
P0=0xff;
CS2=0;
flag=P0_7;
CS2=1;
}while(flag);
RW=0;
P0=com;
CS2=0;
CS2=1;
}
//向从LCD写数据
LCDWriteDat2(unsigned char dat)
{
bit flag;
A0 = 0;
RW=1;
do{
P0=0xff;
CS2=0;
flag=P0_7;
CS2=1;
}while(flag);
A0=1;
RW=0;
P0=dat;
CS2=0;
CS2=1;
}
unsigned char LCDReadDat2()
{
bit flag;
long i;
unsigned char dat;
A0 = 0;
RW=1;
do{
P0=0xff;
CS2=0;
flag=P0_7;
CS2=1;
i++;
}while(flag);
CS2 = 0;
A0=1;
RW=1;
dat=P0;
CS2 = 1;
RW=0;
P0=0xff;
RW=1;
CS2 = 0;
dat=P0;
CS2=1;
return dat;
}
//初始化LCD
void LCD_Init()
{
LCDWriteCom1(0xe2); LCDWriteCom2(0xe2);
LCDWriteCom1(0xa4); LCDWriteCom2(0xa4);
LCDWriteCom1(0xa9); LCDWriteCom2(0xa9);
LCDWriteCom1(0xa0); LCDWriteCom2(0xa0);
LCDWriteCom1(0xc0); LCDWriteCom2(0xc0);
LCDWriteCom1(0xaf); LCDWriteCom2(0xaf);
}
void LCDClear()
{
unsigned char i,j;
for(i=0;i<4;i++)
{
LCDWriteCom1(0xb8|i);
LCDWriteCom2(0xb8|i);
LCDWriteCom1(0);
LCDWriteCom2(0);
for(j=0;j<80;j++)
{
LCDWriteDat1(0x0);
LCDWriteDat2(0x0);
}
}
}
//在x,y点显示一个点
void LCDDrawPoint(unsigned char x,unsigned char y )
{
unsigned char dat,temp;
//设置页
temp=(y>>3);
LCDWriteCom1(0xb8|(temp&3));
LCDWriteCom2(0xb8|(temp&3));
if(x<MAXCOL)
{
LCDWriteCom1(x); //设置行
LCDWriteCom1(0xe0); //打开改写模式
dat=LCDReadDat1(); //读数据
// if(COLOR==0)dat=dat&(!(1<<(y%8))); //计算要写数据
dat=dat|(1<<(y%8));
LCDWriteDat1(dat); //写数据
LCDWriteCom1(0xee); //关闭改写模式
}
else
if(x>MAXCOL)
{ LCDWriteCom2(x-MAXCOL); //设置行
LCDWriteCom2(0xe0); //打开改写模式
dat=LCDReadDat2(); //读数据
// if(COLOR==0) dat=dat&(!(1<<(y%8)));//计算要写数据
dat=dat|(1<<(y%8));
LCDWriteDat2(dat); //写数据
LCDWriteCom2(0xee); //关闭改写模式
}
}
//字符显示
void LCDDrawDatM2(char col, char i, char *pdat)
{
char j;
unsigned char length;
length = 8;
if ((col+length) < MAXCOL)
{
LCDWriteCom1(col);
LCDWriteCom1(0xb8|(i&3)); //设定显示页
for(j=col; j<col+length; j++)
LCDWriteDat1(*(pdat+(j-col)));
return;
}
if (((col+length) >= MAXCOL)&&(col<MAXCOL))
{
LCDWriteCom1(col);
LCDWriteCom1(0xb8|(i&3)); //设定显示页
for(j=col; j<MAXCOL; j++)
LCDWriteDat1(*(pdat+(j-col)));
LCDWriteCom2(0);
LCDWriteCom2(0xb8|(i&3)); //设定显示页
for(j=0; j<MAXCOL; j++)
{
LCDWriteDat2(*(pdat+(MAXCOL-col+j)));
if ((MAXCOL-col+j) >= length)
break;
}
return;
}
else
{
LCDWriteCom2(col-MAXCOL);
LCDWriteCom2(0xb8|(i&3)); //设定显示页
for(j=col-MAXCOL; j<MAXCOL; j++)
{
LCDWriteDat2(*(pdat+(j-col+MAXCOL)));
if ((j-col+MAXCOL) >= length)
break;
}
}
}
//反字符显示
void LCDDrawDatM2_Opposition(char col, char i, char *pdat)
{
char j;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -