MICROCHIP 24LC512读写+串口操作程序!
//===================================================================================////设计时间:2004.09.06
//===================================================================================//
//===================================================================================//
// 程序所用到的头文件
//===================================================================================//
#include
#include
//===================================================================================//
// 宏定义区
//===================================================================================//
#define LCD_SDAT RD7 //LCD SID脚
#define LCD_SCL RD6 //LCD SCL脚
#define LCD_A0 RD5 //LCD A0 脚
#define LCD_RES RD4 //LCD RES脚
#define LCD_CS RC5 //LCD CS 脚
#define TrisInOut_24LC64_SDA TRISC4
#define PinOut_24LC64_SCL RC3
#define PinInOut_24LC64_SDA RC4
//===================================================================================//
// 字库区
//===================================================================================//
const unsigned char caidanh={{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x40,0x40,0x40,0x60,0x40,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xF8,0x08,0x68,0x98,0x00,0xF8,0xA8,0xA8,0xA8,0xA8,0xF8,0x00,0x00,0x00}, //上限
{0x00,0x00,0x08,0x08,0x08,0x08,0x08,0xF8,0x48,0x88,0x08,0x08,0x0C,0x08,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xF8,0x08,0x68,0x98,0x00,0xF8,0xA8,0xA8,0xA8,0xA8,0xF8,0x00,0x00,0x00}, //下限
{0x00,0x00,0x50,0x60,0xFC,0x50,0x40,0x88,0xA8,0xA8,0xFC,0xA8,0xA8,0x88,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xF8,0x28,0x28,0xF8,0xAC,0xA8,0xF8,0x28,0x28,0x00,0x00,0x00}, //精度
{0x00,0x00,0x40,0xC4,0x18,0x00,0xF8,0x88,0xA8,0xF8,0xA8,0x88,0xFC,0x08,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x20,0x10,0x54,0x54,0x94,0x7C,0x94,0x54,0x54,0x54,0x10,0x30,0x00,0x00}, //调零
{0x00,0x00,0xF0,0x90,0x90,0x90,0xF0,0x20,0xA0,0x20,0x20,0xFC,0x20,0x20,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xF0,0x04,0x08,0xE0,0xA8,0xA8,0xE8,0x08,0x08,0xFC,0x08,0x00,0x00}, //时间
{0x00,0x00,0x00,0x08,0x90,0x00,0xE4,0xA4,0xAC,0xF4,0xAC,0xA4,0xE4,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x80,0x40,0xF0,0x0C,0x10,0x50,0x54,0x58,0x50,0x50,0x58,0x50,0x00,0x00}//通信
};
const unsigned char caidanl={{0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x20,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x3F,0x02,0x04,0x03,0x00,0x3F,0x10,0x0A,0x04,0x0A,0x12,0x20,0x00,0x00}, //上限
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x01,0x03,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x3F,0x02,0x04,0x03,0x00,0x3F,0x10,0x0A,0x04,0x0A,0x12,0x20,0x00,0x00}, //下限
{0x00,0x00,0x06,0x01,0x3F,0x02,0x00,0x00,0x3F,0x0A,0x0A,0x2A,0x3F,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x30,0x08,0x27,0x20,0x12,0x16,0x0A,0x16,0x12,0x20,0x20,0x20,0x00,0x00},//精度
{0x00,0x00,0x00,0x0F,0x24,0x12,0x0F,0x00,0x0E,0x0A,0x0E,0x20,0x3F,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x04,0x02,0x06,0x05,0x14,0x15,0x36,0x2D,0x05,0x02,0x06,0x02,0x00,0x00}, //调零
{0x00,0x00,0x0F,0x04,0x04,0x04,0x0F,0x00,0x00,0x13,0x20,0x3F,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3F,0x00,0x00,0x0F,0x04,0x04,0x07,0x10,0x20,0x3F,0x00,0x00,0x00}, //时间
{0x00,0x00,0x20,0x10,0x0F,0x10,0x2F,0x22,0x22,0x2F,0x22,0x2A,0x2F,0x20,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x3D,0x15,0x15,0x15,0x15,0x3D,0x00,0x00,0x00}//通信
};
const unsigned char zhongh={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xE0,0x20,0x20,0x20,0x20,0xFC,0x20,0x20,0x20,0xF0,0x20,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
const unsigned char zhongl={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x03,0x01,0x01,0x01,0x01,0x3F,0x01,0x01,0x01,0x03,0x00,
0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x30,0x30}; //中
const unsigned char qitih={{0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x00,
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //LEL
{0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,
0x80,0x40,0x40,0x40,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //O2
{0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x00,
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //CO
{0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,
0x80,0x40,0x40,0x40,0x80,0x00,0x00,0x70,0x88,
0x08,0x08,0x08,0x38,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} //H2S
};
const unsigned char qitil={{0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,0x00,
0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,0x00,
0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //LEL
{0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,0x00,
0x31,0x28,0x24,0x22,0x21,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //O2
{0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,0x00,
0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //CO
{0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,0x00,
0x31,0x28,0x24,0x22,0x21,0x00,0x00,0x38,0x20,
0x21,0x21,0x22,0x1C,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} //H2S
};
const unsigned char sanjiaoh={0xF0,0xE0,0xC0,0x80};
const unsigned char sanjiaol={0x07,0x03,0x01,0x00}; //菜单指示三角
const unsigned char shijianh={{0x00,0x00,0xF0,0x90,0x90,0x90,0xF0,0x20,0xA0,0x20,0x20,0xFC,0x20,0x20,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0xC0,0xB0,0x8C,0x80,0x80,0x9C,0xA0,0x40,0x80,0x80,0x00,0x00},//时分
{0x00,0x00,0x00,0x00,0x00,0xFC,0x24,0x24,0x24,0x24,0x24,0xFC,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0x88,0xFC,0x08,0x00,0x00,0x00},//月日
{0x00,0x00,0x40,0x20,0x10,0xCC,0x48,0x48,0xF8,0x48,0x48,0x4C,0x48,0x08,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//年
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
};
const unsigned char shijianl={{0x00,0x00,0x0F,0x04,0x04,0x04,0x0F,0x00,0x00,0x13,0x20,0x3F,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0x20,0x20,0x18,0x07,0x00,0x10,0x20,0x1F,0x00,0x00,0x00,0x00,0x00},//时间
{0x00,0x00,0x20,0x10,0x08,0x07,0x01,0x01,0x11,0x21,0x21,0x1F,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x08,0x01F,0x00,0x00,0x00,0x00},//月日
{0x00,0x00,0x02,0x02,0x02,0x03,0x02,0x02,0x3F,0x02,0x02,0x02,0x02,0x02,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//年
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
};
const unsigned char lel={0x81,0xFF,0x81,0x80,0x80,0xC0,0x00,0x81,0xFF,0x89,0x9D,0xC3,0x00,0x81,0xFF,0x81,0x80,0x80,0xC0}; //LEL上半脚
const unsigned char o2={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x81,0x81,0x81,0x7E,0x00,0x00,0xC6,0xA1,0x91,0x89,0x86}; //O2上半脚
const unsigned char h2s={0x00,0x81,0xFF,0x08,0x08,0xFF,0x81,0x00,0xC6,0xA1,0x91,0x89,0x86,0x00,0xC6,0x89,0x89,0x91,0x63}; //H2S上半脚
const unsigned char co={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x81,0x81,0x81,0x43,0x00,0x00,0x7E,0x81,0x81,0x81,0x7E}; //CO上半脚
const unsigned char ppm={0x3E,0x0A,0x0E,0x00,0x3E,0x0A,0x0E,0x00,0x38,0x08,0x38,0x08,0x38,0x00}; //PPM下半脚
const unsigned char bfh={0x06,0xC9,0x36,0x6C,0x93,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //%下半脚
const unsigned char bjing={0x00,0x00,0x00,0x00,0x60,0x7C,0x7E,0xFF,0x7E,0x7C,0x60,0x00,0x00,0x00}; //铃上半脚
const unsigned char dch={{0x38,0x38,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE}, //没电
{0x38,0x38,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0xFE,0xFE,0x82,0xFE}, //一格
{0x38,0x38,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0xFE,0xFE,0x82,0xFE,0xFE,0xFE,0x82,0xFE}, //两格
{0x38,0x38,0xFE,0x82,0xFE,0xFE,0xFE,0x82,0xFE,0xFE,0xFE,0x82,0xFE,0xFE,0xFE,0x82,0xFE}}; //三格
const unsigned char shuzih={{0x00,0xF0,0x0C,0x02,0x02,0x02,0x02,0x0C,0xF0,0x00},//0
{0x00,0x00,0x00,0x04,0x04,0xFE,0x00,0x00,0x00,0x00},//1
{0x00,0x08,0x04,0x02,0x02,0x02,0x82,0x44,0x38,0x00},//2
{0x00,0x08,0x04,0x02,0x82,0x82,0x82,0xC4,0x38,0x00},//3
{0x00,0x00,0xC0,0x30,0x08,0x04,0xFE,0x00,0x00,0x00},//4
{0x00,0xFE,0x82,0x82,0x42,0x42,0x42,0x82,0x00,0x00},//5
{0x00,0xE0,0x98,0x44,0x42,0x42,0x42,0x82,0x0C,0x00},//6
{0x00,0x0E,0x02,0x02,0x02,0xC2,0x32,0x0E,0x02,0x00},//7
{0x00,0x38,0x44,0x82,0x82,0x82,0x82,0x44,0x38,0x00},//8
{0x00,0x78,0x84,0x02,0x02,0x02,0x02,0x84,0xF8,0x00} //9
};
const unsigned char shuzil={{0x00,0x07,0x18,0x20,0x20,0x20,0x20,0x18,0x07,0x00},//0
{0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},//1
{0x00,0x30,0x28,0x24,0x22,0x21,0x20,0x20,0x30,0x00},//2
{0x00,0x0C,0x10,0x20,0x20,0x20,0x20,0x11,0x1F,0x00},//3
{0x00,0x03,0x02,0x02,0x22,0x22,0x3F,0x22,0x22,0x00},//4
{0x00,0x0C,0x10,0x20,0x20,0x20,0x20,0x10,0x0F,0x00},//5
{0x00,0x0F,0x10,0x20,0x20,0x20,0x20,0x10,0x0F,0x00},//6
{0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x00},//7
{0x00,0x0E,0x11,0x20,0x20,0x20,0x20,0x11,0x0E,0x00},//8
{0x00,0x18,0x20,0x21,0x21,0x21,0x11,0x0C,0x03,0x00} //9
};
const unsigned char shjshzh={{0x00,0x7C,0x82,0x01,0x01,0x82,0x7C,0x00}, //0
{0x00,0x02,0x02,0xFF,0x00,0x00,0x00,0x00},//1
{0x00,0x86,0x41,0x21,0x11,0x09,0x86,0x00},//2
{0x00,0xC6,0x01,0x01,0x11,0x11,0xFE,0x00},//3
{0x00,0x38,0x24,0x22,0xFF,0x20,0x20,0x00},//4
{0x00,0xDF,0x09,0x09,0x09,0x09,0xF1,0x00},//5
{0x00,0xFC,0x12,0x09,0x09,0x09,0xF3,0x00},//6
{0x00,0x07,0x01,0xF1,0x0D,0x03,0x01,0x00},//7
{0x00,0xE6,0x19,0x11,0x11,0x19,0xE6,0x00},//8
{0x00,0x9E,0x21,0x21,0x21,0x91,0x7E,0x00} //9
};
const unsigned char shjshzl={{0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00},//0
{0x00,0x01,0x01,0x01,0x01,0x01,0x00,0x00},//1
{0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00},//2
{0x00,0x00,0x01,0x01,0x01,0x01,0x00,0x00},//3
{0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x00},//4
{0x00,0x00,0x01,0x01,0x01,0x01,0x00,0x00},//5
{0x00,0x00,0x01,0x01,0x01,0x01,0x00,0x00},//6
{0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00},//7
{0x00,0x00,0x01,0x01,0x01,0x01,0x00,0x00},//8
{0x00,0x01,0x01,0x01,0x01,0x00,0x00,0x00} //9
};
unsigned char wreerom={0,0,0,0,0,0,0,0,0,0,0,0,0,0};
unsigned char ack_flag=0;
unsigned int lel_counter=0,o2_counter=0x7FFF,co_counter=0,h2s_counter=0x7FFF,ee_flag=0;
uniondycj
{
unsigned charadre;
unsigned int dy;
}dy_cj;
//===================================================================================//
// 系统初始化子程序
//===================================================================================//
void initport(void)
{
IPEN=0;
INTCON=0x00;
INTCON2=0x90;
INTCON3=0x00;
PIE1=0x00;
PIE2=0x00;
TMR0IF=0;
T0CON=0x07;
TRISB=0x3F;
TRISC=0xD0; //设置相应口的输出方式
TRISD=0x02; //设置相应口的输入方式
PORTB=0x39;
PORTC=0xD9;
PORTD=0x00;
ADCON0=0x41; //选择A/D通道为RA0,打开A/D转换器0100,0001 //在工作状态,且使A/D转换时钟为8Tos
ADCON1=0X8A; //转换结果右移,及ADRESH寄存器的高6位为"0"
TRISE1=0;
TRISE2=0;
RE1=1;
RE2=0;
}
//===================================================================================//
// 系统初始化子程序
//===================================================================================//
void sciint(void)
{
TRISC6=1;
TRISC7=1; //将RC6,RC7设置为输入方式,对外部呈高阻状态
SPBRG=0x0B; //将传输的波特率设为19200bps
TXSTA=0x04; //选择异步高速方式传输8 bit数据
RCSTA=0x80; //允许串行口工作
}
//===================================================================================//
// 每一个单位延时为1ms(晶振频率为3.6864MHz)
//===================================================================================//
void delayms(unsigned int dloop1)
{
unsigned char dloop2;
do{dloop2=226;
asm("nop");
do{;}while(--dloop2);
}while(--dloop1);
}
//===================================================================================//
// LCD初始化写数据子程序
//===================================================================================//
void initlceserve(unsigned char lcdmm)
{ unsigned char loop;
LCD_A0=0;
for(loop=8;loop>0;loop--)
{CARRY=0;
lcdmm=lcdmm<<1;
LCD_SDAT=CARRY;
LCD_SCL=1;
LCD_SCL=0;
}
}
//===================================================================================//
// LCD初始化子程序
//===================================================================================//
void initlcd(void)
{
LCD_RES=0;
delayms(1);
LCD_RES=1;
LCD_CS=0;
LCD_SDAT=0;
LCD_SCL=0;
initlceserve(0xA3); //LCD BIAS SET ( A2 1/8;A3 1/65DUTY)
initlceserve(0xA0); //ADC SELECT
initlceserve(0x2F); //POWER CONTROL
initlceserve(0x23); //VOLT REGULATOR RADIO SET
initlceserve(0x81); //REFERENCE VOLT MODE set
initlceserve(0x2C); //REFERENCE VOLT REGset
initlceserve(0xC0); //SHL SELECT
initlceserve(0x40); //DISPLAY START LINE SET
initlceserve(0xAF); //DISPLAY ON/OFF
}
//===================================================================================//
// 写显示数据子程序
//===================================================================================//
void writedata(unsigned char lcddat)
{ unsigned char loop;
LCD_A0=1;
for(loop=8;loop>0;loop--)
{CARRY=0;
lcddat=lcddat<<1;
LCD_SDAT=CARRY;
LCD_SCL=1;
LCD_SCL=0;
}
}
//===================================================================================//
// 写数字上半部
//===================================================================================//
void serveshzh(unsigned char shzval)
{unsigned char lcddat,loop;
for(loop=0;loop<10;loop++)
{lcddat=shuzih;
writedata(lcddat);
}
}
//===================================================================================//
// 写数字下半部
//===================================================================================//
void serveshzl(unsigned char shzval)
{unsigned char lcddat,loop;
for(loop=0;loop<10;loop++)
{lcddat=shuzil;
writedata(lcddat);
}
}
//===================================================================================//
// 写时间数字上半部
//===================================================================================//
void shjshzsvh(unsigned char shzval)
{unsigned char lcddat,loop;
for(loop=0;loop<8;loop++)
{lcddat=shjshzh;
writedata(lcddat);
}
}
//===================================================================================//
// 写时间数字下半部
//===================================================================================//
void shjshzsvl(unsigned char shzval)
{unsigned char lcddat,loop;
for(loop=0;loop<8;loop++)
{lcddat=shjshzl;
writedata(lcddat);
}
}
//===================================================================================//
// 灭数字位
//===================================================================================//
void mieshzserve(void)
{unsigned char loop;
for(loop=0;loop<10;loop++)
writedata(0x00);
}
//===================================================================================//
// 清零子程序
//===================================================================================//
void clearlcd()
{ unsigned char lcdpage=0x00;
unsigned char loop1,loop2;
lcdpage=lcdpage|0xB0;
for(loop1=8;loop1>0;loop1--)
{initlceserve(lcdpage);
initlceserve(0x10);
initlceserve(0x00);
for(loop2=128;loop2>0;loop2--)
writedata(0x00);
lcdpage++;
}
}
//===================================================================================//
// lochflag=1显示LEL值;lochflag=2显示O2值;lochflag=3显示C0值;lochflag=4显示H2S值;
// bjflag=1显示报警图形;bjflag=0不显示报警图形;
//===================================================================================//
void disloch(unsigned int data,unsigned char lochflag,unsigned char bjflag)
{ unsigned char lcdpage,lcdcolh,lcdcoll;
unsigned char loop,gewei,shiwei,baiwei,mfshgflag=0;
data=data%1000;
if(data<10) mfshgflag=1;
else if((data>=10)&&(data<100))
mfshgflag=2;
else mfshgflag=3;
baiwei=(unsigned char)(data/100);
loop=(unsigned char)(data%100);
shiwei=loop/10;
gewei=loop%10;
if((lochflag==1)||(lochflag==2)) lcdpage=0x02;
else lcdpage=0x05; if((lochflag==1)||(lochflag==3))
{lcdcolh=0x10;lcdcoll=0x00;}
else
{lcdcolh=0x13;lcdcoll=0x0E;}
lcdpage=lcdpage|0xB0;
initlceserve(lcdpage);
initlceserve(lcdcolh);
initlceserve(lcdcoll);
for(loop=0;loop<19;loop++)
if(lochflag==1) writedata(lel);
else if(lochflag==2)writedata(o2);
else if(lochflag==3)writedata(co);
else writedata(h2s);
if(mfshgflag!=3) mieshzserve();
else serveshzh(baiwei);
if((mfshgflag==1)&&(lochflag!=2)) mieshzserve();
else serveshzh(shiwei);
if(lochflag==2)
{writedata(0x00);
writedata(0x00);
}
serveshzh(gewei);
for(loop=0;loop<14;loop++)
if(bjflag) writedata(bjing);
else writedata(0x00);
lcdpage++;
initlceserve(lcdpage);
initlceserve(lcdcolh);
initlceserve(lcdcoll);
for(loop=0;loop<19;loop++)
writedata(0x00);
if(mfshgflag!=3) mieshzserve();
else serveshzl(baiwei);
if((mfshgflag==1)&&(lochflag!=2)) mieshzserve();
else serveshzl(shiwei);
if(lochflag==2)
{writedata(0x30);
writedata(0x30);
}
serveshzl(gewei);
for(loop=0;loop<14;loop++)
if((lochflag==1)||(lochflag==2)) writedata(bfh);
else writedata(ppm);
}
//===================================================================================//
// 24LC64 初始化子程序
//===================================================================================//
void Initial_EEPROM(void)
{
TrisInOut_24LC64_SDA=0;
PinOut_24LC64_SCL=1;
asm("nop");
asm("nop");
PinInOut_24LC64_SDA=1;
asm("nop");
asm("nop");
PinOut_24LC64_SCL=0;
asm("nop");
asm("nop");
PinInOut_24LC64_SDA=0;
asm("nop");
asm("nop");
PinOut_24LC64_SCL=1;
asm("nop");
asm("nop");
PinInOut_24LC64_SDA=1;
asm("nop");
asm("nop");
}
//===================================================================================//
// 24LC64 开始子程序
//===================================================================================//
void START24(void)
{
TrisInOut_24LC64_SDA=0;
PinOut_24LC64_SCL=0;
asm("nop");
asm("nop");
PinInOut_24LC64_SDA=1;
asm("nop");
asm("nop");
PinOut_24LC64_SCL=1;
asm("nop");
asm("nop");
PinInOut_24LC64_SDA=0;
asm("nop");
asm("nop");
PinOut_24LC64_SCL=0;
asm("nop");
asm("nop");
}
//===================================================================================//
// 24LC64 停止子程序
//===================================================================================//
void STOP24(void)
{ TrisInOut_24LC64_SDA=0;
PinOut_24LC64_SCL=0;
asm("nop");
asm("nop");
PinInOut_24LC64_SDA=0;
asm("nop");
asm("nop");
PinOut_24LC64_SCL=1;
asm("nop");
asm("nop");
PinInOut_24LC64_SDA=1;
asm("nop");
asm("nop");
PinOut_24LC64_SCL=0;
asm("nop");
asm("nop");
}
//===================================================================================//
// 24LC64 单字节读子程序
//===================================================================================//
unsigned char RBYTE(void)
{
unsigned char loop=0x8;
unsigned char eedata=0;
TrisInOut_24LC64_SDA=1;
while(loop--)
{
eedata<<=1;
PinOut_24LC64_SCL=0;
asm("nop");
asm("nop");
PinOut_24LC64_SCL=1;
asm("nop");
asm("nop");
if(PinInOut_24LC64_SDA)
{
eedata|=0x01;
}
}
PinOut_24LC64_SCL=0;
asm("nop");
asm("nop");
TrisInOut_24LC64_SDA=0;
PinInOut_24LC64_SDA=1;
asm("nop");
asm("nop");
PinOut_24LC64_SCL=1;
return(eedata);
}
//===================================================================================//
// 24LC64 单字节写子程序
//===================================================================================//
void WBYTE(unsigned char eedata)
{
unsigned char loop=0x8;
TrisInOut_24LC64_SDA=0;
while(loop--)
{
PinOut_24LC64_SCL=0;
asm("nop");
asm("nop");
CARRY=0;
eedata=eedata<<1;
PinInOut_24LC64_SDA=CARRY;
asm("nop");
asm("nop");
PinOut_24LC64_SCL=1;
}
asm("nop");
asm("nop");
PinOut_24LC64_SCL=0;
TrisInOut_24LC64_SDA=1;
PinOut_24LC64_SCL=1;
loop=200;
while(loop)
{
if(!PinInOut_24LC64_SDA)
{
break;
}
loop--;
}
PinOut_24LC64_SCL=0;
asm("nop");
asm("nop");
TrisInOut_24LC64_SDA=0;
if(!loop)
{
STOP24();
ack_flag=1;
return; //写EE出错
}
}
//===================================================================================//
// EEPROM24LC64(1024*8bit) 8K
// 写16位数据子程序
//===================================================================================//
unsigned int Write_EEPROM(unsigned char gas_class)
{ unsigned char lc512addr;
unsigned intgas_counter;
if(gas_class==1)
{gas_counter=lel_counter;lc512addr=0xA0;}
else if(gas_class==2)
{gas_counter=o2_counter;lc512addr=0xA0;}
else if(gas_class==3)
{gas_counter=co_counter;lc512addr=0xA2;}
else if(gas_class==4)
{gas_counter=h2s_counter;lc512addr=0xA2;}
dy_cj.dy=gas_counter;
START24(); //START 24
WBYTE(lc512addr); //写设备地址0xA0
WBYTE(dy_cj.adre);
WBYTE(dy_cj.adre);
WBYTE(wreerom);
WBYTE(wreerom);
WBYTE(wreerom);
WBYTE(wreerom);
WBYTE(wreerom);
WBYTE(wreerom);
WBYTE(wreerom);
WBYTE(wreerom);
STOP24();
delayms(5);
gas_counter+=8;
return(gas_counter);
}
//===================================================================================//
// 读16位数据子程序
//===================================================================================//
unsigned int Read_EEPROM(unsigned char lc512addr)
{ unsigned char rdeedata;
rdeedata=lc512addr|0x01;
dy_cj.dy=ee_flag;
START24(); //START 24
WBYTE(lc512addr); //写设备地址0xA0
WBYTE(dy_cj.adre);
WBYTE(dy_cj.adre);
START24(); //START 24
WBYTE(rdeedata); //写读命令0xA1
rdeedata=RBYTE();
STOP24();
ee_flag+=1;
return(rdeedata);
}
//***********************************************************************************//
// 主程序
//***********************************************************************************//
void main(void)
{ unsigned char loop,loop1,rdeedata;
unsigned int value=0,mid=0;
unsigned char rcdata;
initport();
initlcd();
Initial_EEPROM(); //初始化EE
delayms(5);
clearlcd();
sciint();
CREN=1;
TXEN=1;
while(1)
{for(loop=10;loop>0;loop--)
{
for(loop1=0;loop1<8;loop1++)
{rdeedata=Read_EEPROM(0xA2);
value=(unsigned int)rdeedata;
disloch(value,1,0);
delayms(800);
while(1)
{if(RCIF==1) break;
}
rcdata=RCREG;
disloch(rcdata,3,0);
}
if(ee_flag==0x7FFF)
ee_flag=0;
}
if(loop==0)
mid=0;
}
}
//连续读24LC512成功,24LC512地址0xA0,A0脚被拉为低电平
//eerom程序已完成,可直接移植,通信子程序
页:
[1]