192
控制器KS0108
#include #include #include \"zimo.h\" #define RS P2_6 /*\"H\" is send or read the data;\"L\" is the instruction*/ #define RW P3_6 #define E P2_5 /*Operation enable*/ #define CS1 P2_4 #define CS2 P2_3 #define CS3 P2_2 #define DATA P0 #define uchar unsigned char #define uint unsigned int /*---------------------------------------------------------------------------- Delay some time ------------------------------------------------------------------------------*/ void delay10ms(unsigned char x) { unsigned char i,j,k; for(i=0;i for(k=0;k<120;k++); } /*---------------------------------------------------------------------------- Send the instruction to the First KS0108 window ------------------------------------------------------------------------------ --*/ void OutFI(uchar i) { unsigned char data_sta; do{ E=0;RW=1;RS=0;CS1=0;_nop_(); E=1;_nop_(); data_sta=DATA; E=0;RW=0;CS1=1;E=1; }while(data_sta&0x80); E=0;RW=0;RS=0;CS1=0;_nop_(); E=1;_nop_(); DATA=i; _nop_();E=0;RW=1;CS1=1;E=1; } /*---------------------------------------------------------------------------- Send the instruction to the Second KS0108 window. ------------------------------------------------------------------------------ --*/ void OutSI(uchar i) { unsigned char data_sta; do{ E=0;RW=1;RS=0;CS2=0;_nop_(); E=1;_nop_(); data_sta=DATA; E=0;RW=0;CS2=1;E=1; }while(data_sta&0x80); E=0;RW=0;RS=0;CS2=0;_nop_(); E=1;_nop_(); DATA=i; _nop_();E=0;RW=1;CS2=1;E=1; } /*---------------------------------------------------------------------------- Send the instruction to the Third KS0108 window ------------------------------------------------------------------------------ --*/ void OutTI(uchar i) { unsigned char data_sta; do{ E=0;RW=1;RS=0;CS3=0;_nop_(); E=1;_nop_(); data_sta=DATA; E=0;RW=0;CS3=1;E=1; }while(data_sta&0x80); E=0;RW=0;RS=0;CS3=0;_nop_(); E=1;_nop_(); DATA=i; _nop_();E=0;RW=1;CS3=1;E=1; } /*---------------------------------------------------------------------------- Send the data to the First ks0108 Window ------------------------------------------------------------------------------ --*/ void OutFD(uchar i) { unsigned char data_sta; do{ E=0;RW=1;RS=0;CS1=0;_nop_(); E=1;_nop_(); data_sta=DATA; E=0;RW=0;CS1=1;E=1; }while(data_sta&0x80); E=0;RW=0;RS=1;CS1=0;_nop_(); E=1;_nop_(); DATA=i; _nop_();E=0;RW=1;CS1=1;E=1; } /*---------------------------------------------------------------------------- Send the data to the Second ks0108 Window ------------------------------------------------------------------------------ --*/ void OutSD(uchar i) { unsigned char data_sta; do{ E=0;RW=1;RS=0;CS2=0;_nop_(); E=1;_nop_(); data_sta=DATA; E=0;RW=0;CS2=1;E=1; }while(data_sta&0x80); E=0;RW=0;RS=1;CS2=0;_nop_(); E=1;_nop_(); DATA=i; _nop_();E=0;RW=1;CS2=1;E=1; } /*---------------------------------------------------------------------------- Send the data to the Third ks0108 Window ------------------------------------------------------------------------------ --*/ void OutTD(uchar i) { unsigned char data_sta; do{ E=0;RW=1;RS=0;CS3=0;_nop_(); E=1;_nop_(); data_sta=DATA; E=0;RW=0;CS3=1;E=1; }while(data_sta&0x80); E=0;RW=0;RS=1;CS3=0;_nop_(); E=1;_nop_(); DATA=i; _nop_();E=0;RW=1;CS3=1;E=1; } /*---------------------------------------------------------------------------- Read the data to the First ks0108 Window ------------------------------------------------------------------------------ --*/ /*unsigned char RD_data_F() { unsigned char data_sta; do{ E=0;RW=1;RS=0;CS1=0;_nop_(); E=1;_nop_(); data_sta=DATA; E=0;RW=0;CS1=1;E=1; }while(data_sta&0x80); E=0;RW=1;RS=1;CS1=0;_nop_(); E=1;_nop_();_nop_();_nop_(); data_sta=DATA; _nop_();E=0;RW=0;CS1=1;E=1; return (data_sta); } /*---------------------------------------------------------------------------- Read the data to the Second ks0108 Window ------------------------------------------------------------------------------ --*/ /*unsigned char RD_data_S() { unsigned char data_sta; do{ E=0;RW=1;RS=0;CS2=0;_nop_(); E=1;_nop_();_nop_();_nop_(); data_sta=DATA; E=0;RW=0;CS2=1;E=1; }while(data_sta&0x80); E=0;RW=1;RS=1;CS2=0;_nop_(); E=1;_nop_(); data_sta=DATA; _nop_();E=0;CS2=1;E=1; return (data_sta); } /*---------------------------------------------------------------------------- Read the data to the Third ks0108 Window ------------------------------------------------------------------------------ --*/ /*unsigned char RD_data_T() { unsigned char data_sta; do{ E=0;RW=1;RS=0;CS3=0;_nop_(); E=1;_nop_();_nop_();_nop_(); data_sta=DATA; E=0;RW=0;CS3=1;E=1; }while(data_sta&0x80); E=0;RW=1;RS=1;CS3=0;_nop_(); E=1;_nop_(); data_sta=DATA; _nop_();E=0;CS3=1;E=1; return(data_sta); } /*------------------------------------------------------------------------------ Initialize the LCD,The system reset,invoke First time -------------------------------------------------------------------------------- -*/ void InitLCD() { OutFI(0x40); /*Set the Y address 0 */ OutSI(0x40); OutTI(0x40); OutFI(0xb8); /*Set the Page 0 */ OutSI(0xb8); OutTI(0xb8); OutFI(0xc0); /*Set the display start line 0 */ OutSI(0xc0); OutTI(0xc0); OutFI(0x3f); /*Display ON */ OutSI(0x3f); OutTI(0x3f); } /*------------------------------------------------------------------------------ Clear the three ks0108's display ram. Clrscr screen -------------------------------------------------------------------------------- -*/ void Clrscreen() { unsigned char i,j; for(i=0;i<8;i++) { OutFI(0xb8|i); for(j=0;j<;j++) { OutFI(j|0x40); OutFD(0); } } for(i=0;i<8;i++) { OutSI(0xb8|i); for(j=0;j<;j++) { OutSI(j|0x40); OutSD(0); } } for(i=0;i<8;i++) { OutTI(0xb8|i); for(j=0;j<;j++) { OutTI(j|0x40); OutTD(0); } } } /*------------------------------------------------------------------------------ -- Display Chinese ideograph;x_add is the x address;It has 4 layers,0,1,2,3; Width is the Chinese ideograph width;bmp is the table's name -------------------------------------------------------------------------------- -*/ void DrawBmp(uchar x_add,uchar layer,uchar width,uchar *bmp) { unsigned char x; unsigned int i=0; for(x=x_add;x if (x>127) /*The Third KS0108*/ { OutTI((x-128)|0x40); /*Set the x address*/ OutTI(layer|0xb8); /*Set the y address*/ OutTD(bmp[i]); /*Send thd data to LCD ram*/ OutTI((x-128)|0x40); /*Display the down screen*/ OutTI((layer|0xb8)+1); i++; /*Display zimo table address add 1*/ OutTD(bmp[i]); } else if (x>63) /*The Second ks0108*/ { OutSI((x-)|0x40); OutSI(layer|0xb8); OutSD(bmp[i]); OutSI((x-)|0x40); OutSI((layer|0xb8)+1); i++; OutSD(bmp[i]); } else /*The First ks0108*/ { OutFI(x|0x40); OutFI(layer|0xb8); OutFD(bmp[i]); OutFI(x|0x40); OutFI((layer|0xb8)+1); i++; OutFD(bmp[i]); } i++; } } /*------------------------------------------------------------------------------ -- Display Chinese ideograph;x_add is the x address;It has 4 layers,0,1,2,3; Width is the Chinese ideograph width;bmp is the table's name. -------------------------------------------------------------------------------- -*/ void DrawBmp_f(uchar x_add,uchar layer,uchar width,uchar *bmp) { unsigned char x; unsigned int i=0; for(x=x_add;x if (x>127) { OutTI((x-128)|0x40); OutTI(layer|0xb8); OutTD(~bmp[i]); OutTI((x-128)|0x40); OutTI((layer|0xb8)+1); i++; OutTD(~bmp[i]); } else if (x>63) { OutSI((x-)|0x40); OutSI(layer|0xb8); OutSD(~bmp[i]); OutSI((x-)|0x40); OutSI((layer|0xb8)+1); i++; OutSD(~bmp[i]); } else { OutFI(x|0x40); OutFI(layer|0xb8); OutFD(~bmp[i]); OutFI(x|0x40); OutFI((layer|0xb8)+1); i++; OutFD(~bmp[i]); } i++; } } /*------------------------------------------------------------------------------ -- Display indention; x_add is the x address;It has 4 layers,0,1,2,3; Width is the Chinese ideograph width -------------------------------------------------------------------------------- -*/ void _DrawBmp_(uchar x_add,uchar layer,uchar width) { unsigned char x; for(x=x_add;x if (x>127) { OutTI((x-128)|0x40); OutTI(layer|0xb8); OutTD(0); OutTI((x-128)|0x40); OutTI((layer|0xb8)+1); OutTD(0); } else if (x>63) { OutSI((x-)|0x40); OutSI(layer|0xb8); OutSD(0); OutSI((x-)|0x40); OutSI((layer|0xb8)+1); OutSD(0); } else { OutFI(x|0x40); OutFI(layer|0xb8); OutFD(0); OutFI(x|0x40); OutFI((layer|0xb8)+1); OutFD(0); } } } /*------------------------------------------------------------------------------ -- Display indention; x_add is the x address;It has 4 layers,0,1,2,3; Width is the Chinese ideograph width -------------------------------------------------------------------------------- -*/ void _DrawBmp_black(uchar x_add,uchar layer,uchar width) { unsigned char x; for(x=x_add;x if (x>127) { OutTI((x-128)|0x40); OutTI(layer|0xb8); OutTD(0xff); OutTI((x-128)|0x40); OutTI((layer|0xb8)+1); OutTD(0xff); } else if (x>63) { OutSI((x-)|0x40); OutSI(layer|0xb8); OutSD(0xff); OutSI((x-)|0x40); OutSI((layer|0xb8)+1); OutSD(0xff); } else { OutFI(x|0x40); OutFI(layer|0xb8); OutFD(0xff); OutFI(x|0x40); OutFI((layer|0xb8)+1); OutFD(0xff); } } } /*------------------------------------------------------------------------------ -- Display the line display_data_graph is the display graph data -------------------------------------------------------------------------------- -*/ void _DrawBmp_line(uchar x_add,uchar layer,uchar width,uchar display_data_graph) { unsigned char x; unsigned int i=0; for(x=x_add;x if (x>127) { OutTI((x-128)|0x40); OutTI(layer|0xb8); OutTD(display_data_graph); } else if (x>63) { OutSI((x-)|0x40); OutSI(layer|0xb8); OutSD(display_data_graph); } else { OutFI(x|0x40); OutFI(layer|0xb8); OutFD(display_data_graph); } i++; } } /*------------------------------------------------------------------------------ -- Display the column display_data_graph is the display graph data -------------------------------------------------------------------------------- -*/ void _DrawBmp_column(uchar x,uchar width) { unsigned int i=0; if (x>127) { for(i=0;i OutTI((x-128)|0x40); OutTI(i|0xb8); OutTD(0xff); } } else if (x>63) { for(i=0;i OutSI((x-)|0x40); OutSI(i|0xb8); OutSD(0xff); } } else { for(i=0;i OutFI(x|0x40); OutFI(i|0xb8); OutFD(0xff); } } }
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- baomayou.com 版权所有 赣ICP备2024042794号-6
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务