#include <16F877A.h> #device adc=8 #FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD #use delay(clock=11059200) #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) struct lcd_con_bus { int1 unused_0; int1 unused_1; int1 unused_2; int1 wr; int1 rd; int1 cd; int1 reset; int1 unused_7; } lcd;
#define set_tris_lcd(x) set_tris_c(x) #byte lcd = 0x07 #define STX 0x02 #define ETX 0x03 #define EOT 0x04 #define ENQ 0x05 #define BS 0x08 #define CR 0x0D #define LF 0x0A #define DLE 0x10 #define ETB 0x17 #define SPACE 0x20 #define COMMA 0x2C
// T6963C 命令定义 #define LC_CUR_POS 0x21 // 光标位置设置 #define LC_CGR_POS 0x22 // CGRAM偏置地址设置 #define LC_ADD_POS 0x24 // 地址指针位置 #define LC_TXT_STP 0x40 // 文本区首址 #define LC_TXT_WID 0x41 // 文本区宽度 #define LC_GRH_STP 0x42 // 图形区首址 #define LC_GRH_WID 0x43 // 图形区宽度 #define LC_MOD_OR 0x80 // 显示方式:逻辑“或” #define LC_MOD_XOR0x81 // 显示方式:逻辑“异或” #define LC_MOD_AND0x82 // 显示方式:逻辑“与” #define LC_MOD_TCH 0x83 // 显示方式:文本特征 #define LC_DIS_SW 0x90 // 显示开关:D0=1/0:光标闪烁启用/禁用; // D1=1/0:光标显示启用/禁用; // D2=1/0:文本显示启用/禁用; // D3=1/0:图形显示启用/禁用; #define LC_CUR_SHP 0xA0 // 光标形状选择:0xA0-0xA7 表示光标占的行数 #define LC_AUT_WR 0xB0 // 自动写设置 #define LC_AUT_RD 0xB1 // 自动读设置 #define LC_AUT_OVR 0xB2 // 自动读/写结束 #define LC_INC_WR 0xC0 // 数据一次写,地址加 1 #define LC_INC_RD 0xC1 // 数据一次读,地址加 1 #define LC_DEC_WR 0xC2 // 数据一次写,地址减 1 #define LC_DEC_RD 0xC3 // 数据一次读,地址减 1 #define LC_NOC_WR 0xC4 // 数据一次写,地址不变 #define LC_NOC_RD 0xC5 // 数据一次读,地址不变 #define LC_SCN_RD 0xE0 // 屏读 #define LC_SCN_CP 0xE8 // 屏拷贝 #define LC_BIT_OP 0xF0 // 位操作:D0-D2:定义 D0-D7 位;D3:1 置位;0:清除 int8 CurRow,CurCol; // 当前行、列存储,行高 16 点,列宽 8 点 const int8 zifu[]={ 0x00,0x00,0x7C,0xC6,0xC6,0xCE,0xD6,0xD6, // -0-0 0xE6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00, 0x00,0x00,0x18,0x38,0x78,0x18,0x18,0x18, // -1-1 0x18,0x18,0x18,0x7E,0x00,0x00,0x00,0x00, 0x00,0x00,0x7C,0xC6,0x06,0x0C,0x18,0x30, // -2-2 0x60,0xC0,0xC6,0xFE,0x00,0x00,0x00,0x00, 0x00,0x00,0x7C,0xC6,0x06,0x06,0x3C,0x06, // -3-3 0x06,0x06,0xC6,0x7C,0x00,0x00,0x00,0x00, 0x00,0x00,0x0C,0x1C,0x3C,0x6C,0xCC,0xFE, // -4-4 0x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00, 0x00,0x00,0xFE,0xC0,0xC0,0xC0,0xFC,0x0E, // -5-5 0x06,0x06,0xC6,0x7C,0x00,0x00,0x00,0x00, 0x00,0x00,0x38,0x60,0xC0,0xC0,0xFC,0xC6, // -6-6 0xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00, 0x00,0x00,0xFE,0xC6,0x06,0x06,0x0C,0x18, // -7-7 0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00, 0x00,0x00,0x7C,0xC6,0xC6,0xC6,0x7C,0xC6, // -8-8 0xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00, 0x00,0x00,0x7C,0xC6,0xC6,0xC6,0x7E,0x06, // -9-9 0x06,0x06,0x0C,0x78,0x00,0x00,0x00,0x00, 0x00,0x00,0x10,0x38,0x6C,0xC6,0xC6,0xFE, // -A-10 0xC6,0xC6,0xC6,0xC6,0x00,0x00,0x00,0x00, 0x00,0x00,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6, // -V-11 0xC6,0x6C,0x38,0x10,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // -.-12 0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0xFE,0x66,0x62,0x68,0x78,0x68, // -F-13 0x60,0x60,0x60,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x7E, // -+-14 0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE, // ---15 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
}; const int8 tuxing[]={}; const int8 hanzi0[]={
0x01,0xF0,0x21,0x10,0x11,0x10,0x11,0x10,//0"设", 0x01,0x10,0x02,0x0E,0xF4,0x00,0x13,0xF8, 0x11,0x08,0x11,0x10,0x10,0x90,0x10,0xA0, 0x14,0x40,0x18,0xB0,0x13,0x0E,0x0C,0x04, 0x02,0x00,0x01,0x00,0x7F,0xFE,0x40,0x02,//1"定", 0x80,0x24,0x1F,0xF0,0x01,0x00,0x01,0x00, 0x11,0x20,0x11,0xF0,0x11,0x00,0x11,0x00, 0x11,0x00,0x29,0x06,0x47,0xFC,0x80,0x00
0x02,0x00,0x01,0x00,0x7F,0xFE,0x48,0x02,//2"实", 0x86,0x84,0x02,0x80,0x10,0x80,0x0C,0x80, 0x04,0x84,0xFF,0xFE,0x01,0x00,0x01,0x40, 0x02,0x20,0x04,0x10,0x18,0x0C,0x60,0x04, 0x00,0x08,0x7D,0xFC,0x44,0x00,0x48,0x00,//3"际", 0x48,0x00,0x50,0x04,0x4B,0xFE,0x48,0x20, 0x44,0x20,0x44,0xA8,0x44,0xA4,0x69,0x22, 0x52,0x22,0x40,0x20,0x40,0xA0,0x40,0x40, 0x02,0x00,0x02,0x00,0x02,0x10,0x7F,0xF8,//4"电", 0x42,0x10,0x42,0x10,0x7F,0xF0,0x42,0x10, 0x42,0x10,0x7F,0xF0,0x42,0x10,0x02,0x00, 0x02,0x04,0x02,0x04,0x01,0xFC,0x00,0x00, 0x00,0x08,0x3F,0xFC,0x20,0x80,0x20,0x80,//5"压", 0x20,0x80,0x20,0x80,0x20,0x88,0x2F,0xFC, 0x20,0x80,0x20,0xA0,0x20,0x98,0x20,0x88, 0x40,0x80,0x40,0x84,0x9F,0xFE,0x00,0x00
0x00,0x80,0x40,0x48,0x37,0xFC,0x10,0x40,//6"流", 0x80,0x90,0x61,0x08,0x27,0xFC,0x08,0x04, 0x11,0x50,0x21,0x50,0xE1,0x50,0x21,0x50, 0x21,0x52,0x21,0x52,0x22,0x4E,0x24,0x40 };
const int8 hanzi1[]={
0x00,0x00,0x22,0x08,0x11,0x10,0x10,0xA0,//0"说", 0x03,0xF8,0x02,0x08,0xF2,0x08,0x12,0x08, 0x13,0xF8,0x12,0xA8,0x10,0xA0,0x10,0xA0, 0x15,0x22,0x19,0x22,0x12,0x1E,0x04,0x00, 0x00,0x04,0x04,0xFE,0x7E,0x84,0x44,0x84,//1"明", 0x44,0x84,0x44,0xFC,0x7C,0x84,0x44,0x84, 0x44,0x84,0x44,0xFC,0x7C,0x84,0x44,0x84, 0x01,0x04,0x01,0x04,0x02,0x14,0x04,0x08
0x10,0x40,0x10,0x20,0x10,0x00,0x13,0xFE,//2"按", 0xFA,0x02,0x14,0x44,0x10,0x40,0x3F,0xFE, 0xD0,0x88,0x10,0x88,0x11,0x08,0x10,0x90, 0x10,0x60,0x10,0x50,0x50,0x8C,0x23,0x04
0x20,0x10,0x27,0x10,0x39,0x7C,0x41,0x14,//3"键", 0x82,0xFE,0x7A,0x14,0x24,0x7C,0x27,0x10, 0xF9,0x7C,0x21,0x10,0x25,0x14,0x22,0xFE, 0x2A,0x10,0x35,0x10,0x28,0x96,0x00,0x7C };
include "D:\GE LI HUI\16F877A\240X128LCD\main.h" // 状态位判断忙否 void lcd_busy(int8 i) { int8 m=0x00; set_tris_b(0xff); lcd.cd=1; lcd.rd=1; lcd.wr=1; lcd.rd=0; while((m&i)==0) { m=input_b(); } lcd.rd=1; set_tris_b(0x00); } // 状态位 STA1,STA0 判断 void lcd_busy01() { lcd_busy(1); lcd_busy(2); }
// 写数据的函数 void lcd_wr_dat(int8 dat) { lcd_busy01(); lcd.cd=0; output_b(dat); lcd.wr=0; delay_us(10); lcd.wr=1; } // 写指令的函数 void lcd_wr_cmd(int8 cmd) { lcd_busy01(); output_b(cmd); lcd.wr=0; delay_us(10); lcd.wr=1; }
// 自动写数据 void lcd_auto_wr(int8 dat) { lcd_busy(8); lcd.cd=0; output_b(dat); lcd.wr=0; delay_us(10); lcd.wr=1; } // 读数据的函数 int8 lcd_rd_dat() { int8 dat; lcd_busy01(); lcd.cd=0; lcd.rd=0; delay_us(10); dat=input_b(); lcd.rd=1; return dat; } // 写双参数的函数 void lcd_set_2(int8 cmd,int8 da1,int8 da2) { lcd_wr_dat(da1); lcd_wr_dat(da2); lcd_wr_cmd(cmd); }
// 写16位数据的函数 void lcd_set16(int8 cmd,int16 dat) { int dal,dah; dal=dat; dah=dat>>8; lcd_wr_dat(dal); lcd_wr_dat(dah); lcd_wr_cmd(cmd); } // 写单参数的函数 void lcd_set_1(int8 cmd,int8 da1) { lcd_wr_dat(da1); lcd_wr_cmd(cmd); } // 写无参数的函数 void lcd_set_0(int8 cmd) { lcd_wr_cmd(cmd); } // 设置当前地址 void lcd_setpos(int8 row,int8 col) { int8 ipos; ipos=row*30+col; lcd_set_2(LC_ADD_POS,ipos&0xff,ipos/256); CurRow=row; CurCol=col; } // 设置当前显示行、列 void cursor(int8 Row, int8 Col) { lcd_setpos(row*16,col); } // 清屏 void lcd_clr() { int16 i; lcd_set_2(LC_ADD_POS,0x00,0x00); lcd_set_0(LC_AUT_WR); for(i=0;i<128*30;i++) { lcd_auto_wr(0x00); } lcd_set_0(LC_AUT_OVR); lcd_set_2(LC_ADD_POS,0x00,0x00); } //划横线程序 void lcd_heng(int16 hang) { int8 i; for(i=0;i<30;i++) { lcd_set16(LC_ADD_POS,hang*30+i); lcd_set_1(LC_NOC_WR,0xff); } } //显示8x16字符 x表示横 y表示纵 void lcd0_zifu8x16(int16 x,int16 y,int16 n) { int16 i; int16 addr; addr=x+(y*30*16)+(y+1)*90; for(i=0;i<16;i++) { lcd_set16(LC_ADD_POS,addr+i*30+30); lcd_set_1(LC_NOC_WR,zifu[i+n*16]); } }
void lcd1_zifu8x16(int16 x,int16 y,int16 n) { int16 i; int16 addr; addr=x+(y*30*16)+(y+1)*90; for(i=0;i<16;i++) { lcd_set16(LC_ADD_POS,addr+i*30+210); lcd_set_1(LC_NOC_WR,zifu[i+n*16]); } } //显示16x16汉字 void lcd0_hanzi16x16(int16 x,int16 y,int16 n) { int16 i; int16 addr; addr=x+(y*30*16)+(y+1)*90; // addr=x*2+y*570+90; for(i=0;i<16;i++) { lcd_set16(LC_ADD_POS,addr+i*30); lcd_set_1(LC_INC_WR,hanzi0[i*2+n*32]); lcd_set_1(LC_INC_WR,hanzi0[i*2+n*32+1]); } }
void lcd1_hanzi16x16(int16 x,int16 y,int16 n) { int16 i; int16 addr; addr=x+(y*30*16)+(y+1)*90; // addr=x*2+y*570+90; for(i=0;i<16;i++) { lcd_set16(LC_ADD_POS,addr+i*30+150); lcd_set_1(LC_INC_WR,hanzi1[i*2+n*32]); lcd_set_1(LC_INC_WR,hanzi1[i*2+n*32+1]); } }
//显示24x24汉字 void lcd_hanzi24x24(int16 x,int16 y,int16 n) { int16 i; int16 addr; addr=x*3+(y*30*24); for(i=0;i<24;i++) { lcd_set16(LC_ADD_POS,addr+i*30); lcd_set_1(LC_INC_WR,hanzi0[i*3+n*72]); lcd_set_1(LC_INC_WR,hanzi0[i*3+n*72+1]); lcd_set_1(LC_INC_WR,hanzi0[i*3+n*72+2]); } }
//图形全屏显示240*128 void lcd_tu_fu() { int16 i; int16 m=0x0f00; lcd_set_2(LC_ADD_POS,0x00,0x00); lcd_set_0(LC_AUT_WR); for(i=0;i<m;i++) { lcd_auto_wr(tuxing); }
lcd_set_0(LC_AUT_OVR); lcd_set_2(LC_ADD_POS,0x00,0x00); }
//第一行显示 void lcd_diyi() { lcd_heng(0); lcd_heng(1); lcd0_hanzi16x16(2,0,0);//设 lcd0_hanzi16x16(4,0,1);//定 lcd0_hanzi16x16(6,0,4);//电 lcd0_hanzi16x16(8,0,5);//压 lcd0_zifu8x16(19,0,11);//V lcd_heng(20); lcd0_hanzi16x16(2,1,2);//实 lcd0_hanzi16x16(4,1,3);//际 lcd0_hanzi16x16(6,1,4);//电 lcd0_hanzi16x16(8,1,5);//压 lcd0_zifu8x16(19,1,11);//V lcd_heng(39); lcd0_hanzi16x16(2,2,2);//实 lcd0_hanzi16x16(4,2,3);//际 lcd0_hanzi16x16(6,2,4);//电 lcd0_hanzi16x16(8,2,6);//流 lcd0_zifu8x16(19,2,10);//A lcd_heng(58); lcd_heng(59); lcd_heng(60); lcd_heng(125); lcd_heng(126); lcd_heng(127);
}
void shuoming() { lcd1_hanzi16x16(2,3,0);//说 lcd1_hanzi16x16(4,3,1);//明
lcd1_hanzi16x16(2,4,2);//按 lcd1_zifu8x16(4,4,13);//F lcd1_zifu8x16(5,4,1);//1 lcd1_hanzi16x16(6,4,3);//键 lcd1_zifu8x16(8,4,14);//+ lcd1_zifu8x16(9,4,1);//1 lcd1_zifu8x16(10,4,0);//0 lcd1_zifu8x16(11,4,11);//V
lcd1_hanzi16x16(16,4,2);//按 lcd1_zifu8x16(18,4,13);//F lcd1_zifu8x16(19,4,2);//2 lcd1_hanzi16x16(20,4,3);//键 lcd1_zifu8x16(22,4,15);//- lcd1_zifu8x16(23,4,1);//1 lcd1_zifu8x16(24,4,0);//0 lcd1_zifu8x16(25,4,11);//V
lcd1_hanzi16x16(2,5,2);//按 lcd1_zifu8x16(4,5,13);//F lcd1_zifu8x16(5,5,3);//3 lcd1_hanzi16x16(6,5,3);//键 lcd1_zifu8x16(8,5,14);//+ lcd1_zifu8x16(9,5,1);//1 lcd1_zifu8x16(10,5,0);//0 lcd1_zifu8x16(11,5,0);//0 lcd1_zifu8x16(12,5,11);//V
lcd1_hanzi16x16(16,5,2);//按 lcd1_zifu8x16(18,5,0);//0 lcd1_hanzi16x16(19,5,3);//键 lcd1_zifu8x16(21,5,15);//- lcd1_zifu8x16(22,5,1);//1 lcd1_zifu8x16(23,5,0);//0 lcd1_zifu8x16(24,5,0);//0 lcd1_zifu8x16(25,5,11);//V
}
//在特定的位置显示电流 void shuzi_I(int16 dat,int8 hang) { int8 dian0=0,dian1=0,dian2=0,dian3=0; dian0=dat/1000; dian1=(dat%1000)/100; dian2=(dat%100)/10; dian3=(dat%10); lcd0_zifu8x16(13,hang,dian0); lcd0_zifu8x16(14,hang,12); lcd0_zifu8x16(15,hang,dian1); lcd0_zifu8x16(16,hang,dian2); lcd0_zifu8x16(17,hang,dian3); }
//在特定的位置显示电压 void shuzi_V(int16 dat,int8 hang) { int8 qia=0,bai=0,shi=0,gee=0; qia=dat/1000; bai=(dat%1000)/100; shi=(dat%100)/10; gee=(dat%10); lcd0_zifu8x16(13,hang,0); lcd0_zifu8x16(14,hang,qia); lcd0_zifu8x16(15,hang,bai); lcd0_zifu8x16(16,hang,shi); lcd0_zifu8x16(17,hang,gee);
}
// LCM 初始化 void lcd_init() { lcd_set_2(LC_TXT_STP,0x00,0x00); lcd_set_2(LC_TXT_WID,0x1e,0x00); lcd_set_2(LC_GRH_STP,0x00,0x00); lcd_set_2(LC_GRH_WID,0x1e,0x00); lcd_set_0(LC_CUR_SHP|0x00); lcd_set_0(LC_MOD_OR); lcd_set_0(LC_DIS_SW|0x08); }
void main() { int16 a=0; set_tris_b(0x00); set_tris_c(0x07); lcd.reset=0; lcd.reset=1; lcd_init(); lcd_clr(); // lcd_zifu8x8(0,10,2); //!// lcd_tu_fu(); lcd_diyi(); shuzi_V(2154,0); shuzi_V(2154,1); shuzi_I(1234,2); shuoming(); // lcd_hanzi16x16(0,0,0); // lcd_hanzi24x24(0,0,0); while(1) { shuzi_V(a,0); shuzi_V(a,1); a++; delay_ms(1); } } |