📄 8255.c
字号:
#include <iom128v.h>
#define setbit(x,y) x|=(1<<y) //将X的第Y位置1
#define clrbit(x,y) x&=~(1<<y) //将X的第Y位清0
//定义8255
#define WRON PORTC&=~(1<<0)
#define WROFF PORTC|=(1<<0)
#define A01 PORTC|=(1<<1)
#define A00 PORTC&=~(1<<1)
#define A11 PORTC|=(1<<6)
#define A10 PORTC&=~(1<<6)
#define shuju PORTB
#define reset82550 PORTC&=~(1<<7)
#define reset82551 PORTC|=(1<<7)
//定义LCD
#define Disp_On 0x3f
#define Disp_Off 0x3e
#define Col_Add 0x40
#define Page_Add 0xb8
#define Start_Line 0xc0
#define RST1 PORTE|=(1<<7)
#define RST0 PORTE&=~(1<<7)
#define E1 PORTE|=(1<<6)
#define E0 PORTE&=~(1<<6)
#define RW1 PORTE|=(1<<5)
#define RW0 PORTE&=~(1<<5)
#define RS1 PORTE|=(1<<3)
#define RS0 PORTE&=~(1<<3)
#define LCDCS11 PORTE|=(1<<1)
#define LCDCS10 PORTE&=~(1<<1)
#define LCDCS21 PORTE|=(1<<2)
#define LCDCS20 PORTE&=~(1<<2)
//定义key
#define key PIND
//定义TLC5615
#define SPI_DATA0 PORTF&=~(1<<0)
#define SPI_DATA1 PORTF|=(1<<0)
#define SPI_CLK1 PORTD|=(1<<6)
#define SPI_CLK0 PORTD&=~(1<<6)
#define CS_DA0 PORTD&=~(1<<7)
#define CS_DA1 PORTD|=(1<<7)
unsigned int writeDA;
//定义TLC2543
#define tlc2543_clk1 PORTD|=(1<<5)
#define tlc2543_clk0 PORTD&=~(1<<5)
#define tlc2543_din1 PORTF|=(1<<1)
#define tlc2543_din0 PORTF&=~(1<<1)
#define tlc2543_cs1 PORTF|=(1<<3)
#define tlc2543_cs0 PORTF&=~(1<<3)
#define tlc2543_dout (PINF&0X04)
//定义继电器
#define sw0 PORTC&=~(1<<5)
#define sw1 PORTC|=(1<<5)
//定义ad9851
#define wclk0 PORTF&=~(1<<5)
#define wclk1 PORTF|=(1<<5)
#define fqud0 PORTF&=~(1<<6)
#define fqud1 PORTF|=(1<<6)
#define reset98511 PORTF|=(1<<7)
#define reset98510 PORTF&=~(1<<7)
#define ad9851shuju PORTA
//报警
//#define erjiguanON PORTE&=~(1<<0)
//#define erjiguanOFF PORTE|=(1<<0)
#define fengmingqiON PORTD&=~(1<<4)
#define fengmingqiOFF PORTD|=(1<<4)
signed char jianzhi[5]={0,0,0,0,0};
unsigned char kongzhi[5];
signed long int pinlv;
unsigned int startAD(unsigned char CHN) ;
void tongdao(unsigned char i);
unsigned int date1,date;
float date2;
unsigned char time=0;
#pragma interrupt_handler guoliujianche:6
const unsigned char huan[]={0x0A,0x92,0x62,0x9E,0x02,0x18,0x87,0x74,0x84,0x14,0x0C,0x00,0x02,0x01,0x00,0x04,
0x05,0x02,0x01,0x00,0x01,0x02,0x04,0x00
};
const unsigned char ying[]={0x08,0xF9,0x02,0x00,0xFE,0x42,0x41,0xFE,0x02,0x82,0xFE,0x00,0x06,0x01,0x02,0x02,
0x04,0x04,0x04,0x05,0x04,0x04,0x04,0x00
};
const unsigned char shi[]={0x10,0x08,0xFE,0x01,0x7A,0xCA,0x4A,0xFF,0x4A,0x4A,0x7A,0x00,0x00,0x00,0x07,0x04,
0x04,0x02,0x01,0x02,0x04,0x04,0x04,0x00
};
const unsigned char yong[]={0x00,0xFF,0x49,0x49,0x49,0xFF,0x49,0x49,0x49,0xFF,0x00,0x00,0x06,0x01,0x00,0x00,
0x00,0x07,0x00,0x04,0x04,0x07,0x00,0x00
};
const unsigned char shu[]= {0xA5,0x96,0xCC,0xBF,0x96,0xA5,0x18,0x67,0x84,0x7C,0x04,0x00,0x04,0x05,0x02,0x02,
0x03,0x04,0x04,0x02,0x01,0x02,0x04,0x00
};
const unsigned char kong[]={0x44,0x24,0xFF,0x14,0x26,0x52,0x4A,0xC3,0x4A,0x52,0x26,0x00,0x04,0x04,0x07,0x00,
0x04,0x04,0x04,0x07,0x04,0x04,0x04,0x00
};
const unsigned char yuan[]={0x08,0xD1,0x3A,0x80,0x7F,0x01,0x7D,0x57,0xD5,0x55,0x7D,0x00,0x01,0x07,0x02,0x01,
0x04,0x02,0x05,0x04,0x07,0x01,0x06,0x00
};
const unsigned char wen[]={0x8A,0x6A,0xFE,0x29,0x41,0xAC,0xAB,0xAA,0xAE,0xAA,0xF8,0x00,0x01,0x00,0x07,0x02,
0x01,0x07,0x04,0x06,0x04,0x05,0x02,0x00
};
const unsigned char dya[]= {0x00,0xFF,0x01,0x21,0x21,0xFD,0x21,0x61,0xA1,0x21,0x01,0x00,0x06,0x01,0x04,0x04,
0x04,0x07,0x04,0x04,0x04,0x05,0x04,0x00
};
const unsigned char ddian[]= {0x00,0xFC,0x94,0x94,0x94,0xFF,0x94,0x94,0x94,0xFE,0x04,0x00,0x00,0x01,0x00,0x00,
0x00,0x03,0x04,0x04,0x04,0x04,0x06,0x00
};
const unsigned char chu[]= {0x34,0x2F,0xF4,0xA4,0xE8,0xA4,0xEA,0x09,0xEA,0x04,0xE8,0x00,0x01,0x01,0x07,0x00,
0x07,0x02,0x07,0x00,0x01,0x04,0x07,0x00
};
const unsigned char cu[]={0x00,0xDE,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0xDE,0x00,0x00,0x00,0x07,0x04,0x04,
0x04,0x07,0x04,0x04,0x04,0x07,0x00,0x00
};
const unsigned char heng[]={0x18,0xFF,0x08,0x02,0xFA,0x2A,0x2A,0x2A,0x2A,0xFB,0x02,0x00,0x00,0x07,0x00,0x04,
0x05,0x05,0x05,0x05,0x05,0x05,0x04,0x00
};
const unsigned char ru []={0x00,0x00,0x00,0xC1,0x31,0x0E,0x30,0xC0,0x00,0x00,0x00,0x00,0x04,0x02,0x01,0x00,
0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x00
};
const unsigned char you[]={0x42,0x22,0x12,0xFA,0x4E,0x4B,0x4A,0x4A,0xFA,0x02,0x02,0x00,0x00,0x00,0x00,0x07,
0x01,0x01,0x01,0x05,0x07,0x00,0x00,0x00
};
const unsigned char xiao[]={0x24,0x14,0x4D,0x86,0x6C,0x14,0x08,0x7F,0x84,0x7C,0x04,0x00,0x04,0x02,0x01,0x00,
0x03,0x04,0x02,0x01,0x01,0x02,0x04,0x00
};
const unsigned char zhixian[]={0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
const unsigned char dliu[]= {0x11,0xA6,0x70,0x02,0xD2,0x1A,0xD7,0x12,0xDA,0x32,0x02,0x00,0x01,0x07,0x04,0x02,
0x01,0x00,0x07,0x00,0x07,0x04,0x07,0x00
};
const unsigned char guo[]= {0x11,0x16,0xF0,0x04,0x14,0x64,0x04,0x04,0xFF,0x04,0x04,0x00,0x04,0x02,0x01,0x02,
0x04,0x04,0x05,0x05,0x05,0x04,0x04,0x00
};
const unsigned char si[]={0x88,0x86,0xA2,0xCA,0x92,0x83,0xFA,0x82,0x82,0x8A,0x86,0x00,0x00,0x04,0x04,0x04,
0x02,0x01,0x00,0x01,0x02,0x04,0x00,0x00
};
const unsigned char ji[]={0xFF,0x81,0x99,0xE7,0x08,0xC9,0x09,0xF9,0x09,0xC9,0x08,0x00,0x07,0x00,0x00,0x02,
0x01,0x04,0x04,0x07,0x00,0x00,0x03,0x00
};
const unsigned char yu[]={0x11,0x15,0xFD,0x13,0x30,0x01,0xFD,0x07,0xF5,0x05,0xFD,0x00,0x04,0x04,0x07,0x00,
0x04,0x04,0x02,0x01,0x01,0x02,0x04,0x00
};
const unsigned char zhi[]= {0x10,0x17,0xF5,0x55,0x57,0x5D,0x57,0x55,0xF5,0x17,0x10,0x00,0x04,0x04,0x07,0x05,
0x05,0x05,0x05,0x05,0x07,0x04,0x04,0x00
};
const unsigned char bo[]={0x08,0xD1,0x3A,0x00,0xFC,0x24,0xE4,0x3F,0xA4,0x64,0x0C,0x00,0x01,0x07,0x04,0x03,
0x04,0x04,0x02,0x01,0x02,0x04,0x04,0x00
};
const unsigned char xing[]={0x12,0x12,0xFE,0x12,0x12,0xFF,0x92,0x48,0x24,0x13,0x80,0x00,0x04,0x03,0x00,0x00,
0x00,0x07,0x04,0x02,0x02,0x01,0x00,0x00
};
const unsigned char zfv[]= {0x20,0xE0,0x20,0x80,0x60,0x20,0x00,0x00,0x03,0x01,0x00,0x00
};
const unsigned char zfA[]= {0x00,0xE0,0x9C,0xF0,0x80,0x00,0x02,0x03,0x00,0x00,0x03,0x02
};
const unsigned char zfm[]={0xE0,0x20,0xE0,0x20,0xC0,0x00,0x03,0x00,0x03,0x00,0x03,0x00
};
const unsigned char sz0[]={0xF8,0x04,0x04,0x04,0xF8,0x00,0x01,0x02,0x02,0x02,0x01,0x00
};
const unsigned char sz1[]={0x00,0x08,0xFC,0x00,0x00,0x00,0x00,0x02,0x03,0x02,0x00,0x00
};
const unsigned char sz2[]={0x18,0x84,0x44,0x24,0x18,0x00,0x03,0x02,0x02,0x02,0x02,0x00
};
const unsigned char sz3[]={0x08,0x04,0x24,0x24,0xD8,0x00,0x01,0x02,0x02,0x02,0x01,0x00
};
const unsigned char sz4[]={0x40,0xB0,0x88,0xFC,0x80,0x00,0x00,0x00,0x00,0x03,0x02,0x00
};
const unsigned char sz5[]={0x3C,0x24,0x24,0x24,0xC4,0x00,0x01,0x02,0x02,0x02,0x01,0x00
};
const unsigned char sz6[]={0xF8,0x24,0x24,0x2C,0xC0,0x00,0x01,0x02,0x02,0x02,0x01,0x00
};
const unsigned char sz7[]={0x0C,0x04,0xE4,0x1C,0x04,0x00,0x00,0x00,0x03,0x00,0x00,0x00
};
const unsigned char sz8[]={0xD8,0x24,0x24,0x24,0xD8,0x00,0x01,0x02,0x02,0x02,0x01,0x00
};
const unsigned char sz9[]={0x38,0x44,0x44,0x44,0xF8,0x00,0x00,0x03,0x02,0x02,0x01,0x00
};
const unsigned char xiaoshu[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00
};
const unsigned char kongke[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
const unsigned char dqing[]= {0x10,0xF1,0x02,0x00,0x2A,0xEA,0xAA,0xBF,0xAA,0xEA,0x2A,0x00,0x00,0x07,0x02,0x01,
0x00,0x07,0x02,0x02,0x02,0x07,0x00,0x00
};
const unsigned char chong[]= {0x04,0x05,0xF5,0x55,0x55,0xFF,0x55,0x55,0xF5,0x05,0x04,0x00,0x04,0x05,0x05,0x05,
0x05,0x07,0x05,0x05,0x05,0x05,0x04,0x00
};
const unsigned char qi[]= {0x00,0x00,0xFE,0xD2,0x52,0x53,0x52,0x52,0x52,0xDE,0x00,0x00,0x04,0x03,0x00,0x07,
0x04,0x04,0x04,0x04,0x04,0x07,0x00,0x00
};
const unsigned char pin[]={0x90,0x5E,0xF0,0x1F,0xD4,0x11,0xFD,0x05,0xF7,0x05,0xFD,0x00,0x04,0x04,0x02,0x01,
0x04,0x04,0x02,0x01,0x00,0x01,0x06,0x00
};
const unsigned char lv[]={0x42,0x46,0x2A,0x52,0x6A,0xD7,0x6A,0x52,0x2A,0x46,0x02,0x00,0x01,0x01,0x01,0x01,
0x01,0x07,0x01,0x01,0x01,0x01,0x01,0x00
};
const unsigned char zfM[]={0xFC,0x3C,0xC0,0x3C,0xFC,0x00,0x03,0x00,0x03,0x00,0x03,0x00
};
const unsigned char zfk[]={0x04,0xFC,0x80,0xE0,0x20,0x20,0x02,0x03,0x02,0x00,0x03,0x02
};
const unsigned char *num[]={sz0,sz1,sz2,sz3,sz4,sz5,sz6,sz7,sz8,sz9};
//8255
void delay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<10;j++)
;
}
/*void writePC(unsigned char d,unsigned char x)//PA的第d个端口置X x=0或1
{
WROFF; LEOFF;
shuju=0X09;
delay(1);
LEON ;
delay(1);
LEOFF;
delay(1);
if(x==1)
shuju=lastPA|(1<<d);
if(x==0)
shuju=lastPA&~(1<<d);
lastPA=shuju;
WRON ;
delay(5);WROFF;
}*/
/*void writePB(unsigned char d)
{
WROFF;
LEOFF;
shuju=0X05;
delay(1);
LEON ;
delay(1);
LEOFF;
delay(1);
shuju=d;
WRON ;
delay(5);WROFF;
}*/
void writePA(unsigned char d)
{
WROFF;
A00;
A10;
delay(1);
shuju=d;
WRON ;
delay(5);
WROFF;
}
void writecommand(unsigned char d)
{ WROFF;
A01;
A11;
delay(1);
shuju=d;
WRON ;
delay(5);
WROFF;
}
//LCD
void write_command(unsigned char cmdcode)
{
RS0;
RW0;
writePA(cmdcode);
delay(1);
E1;
delay(1);
E0;
}
void write_data(unsigned char Dispdata)
{
RS1;
RW0;
writePA(Dispdata);
delay(1);
E1;
delay(1);
E0;
}
//通道
void tongdao(unsigned char i)
{if(i==1) {PORTC&=~(1<<4);PORTC&=~(1<<3); PORTC|=(1<<2);}
if(i==2) {PORTC|=(1<<4);;PORTC&=~(1<<3); PORTC|=(1<<2);}
if(i==0) {PORTC&=~(1<<4);PORTC&=~(1<<3); PORTC&=~(1<<2);}
}
void Clr_Scr() //清屏
{
unsigned char j,k;
for(k=0;k<8;k++)
{
LCDCS21;
LCDCS10;
delay(10);
write_command((Page_Add+k));
write_command((Col_Add+0));
for(j=0;j<64;j++)
write_data(0x00);
LCDCS20;
LCDCS11;
delay(10);
write_command((Page_Add+k));
write_command((Col_Add+0));
for(j=64;j<128;j++)
write_data(0x00);
}
}
void disp_zf(unsigned char Y,unsigned char X, const unsigned char *sz)
{
unsigned char j=0,i=0;
for(j=0;j<2;j++)
{
write_command((Page_Add+Y+j));
write_command((Col_Add+X));
for(i=0;i<6;i++)
write_data(sz[6*j+i]);
}
}
/*---------------------指定位置显示汉字16*16-----------------------*/
void disp_hz(unsigned char Y,unsigned char X, const unsigned char *hz)
{
unsigned char j=0,i=0;
for(j=0;j<2;j++)
{
write_command((Page_Add+Y+j)); //列在前行在后
write_command((Col_Add+X));
for(i=0;i<12;i++)
write_data(hz[12*j+i]);
}
}
/*------------------初始化LCD屏--------------------------*/
void init_lcd()
{
RST0;
delay(1);
RST1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -