STC89C52的机器,参考了网上的代码,改了半天没效果,哪个老大支持下下!19264的屏,KS0108芯片!
#include <reg52.h>
#include <stdlib.h>
#include <intrins.h>
#include <stdio.h>
/********************引脚定义********************/
sbit RS =P3^0; //数据指令
sbit RW =P3^1; //读写
sbit E =P3^2; //使能
sbit CSL =P3^3; //左片选
sbit CSM =P3^4; //中片选
sbit CSR =P3^5; //右片选
sbit RST =P3^6;
unsigned char Page; //页 地址
unsigned char Col; //列 地址
unsigned char code BMP1[];
unsigned char code BMP2[];
void Delay(unsigned int MS);
void wtcom(void);
/***************************/
/*检查Busy */
/***************************/
void BusyL(void)
{
CSL= 1;
CSM= 0;
CSR= 0;
wtcom();
}
void BusyM(void)
{
CSL= 0;
CSM= 1;
CSR= 0;
wtcom();
}
void BusyR(void)
{
CSL= 0;
CSM= 0;
CSR= 1;
wtcom();
}
void wtcom(void)
{
RS = 0; //指令
RW = 1;
P1 = 0xFF; //输出0xff以便读取正确
E = 1;
_nop_();_nop_();_nop_();
while(P1 & 0x80); //Status Read Bit7 = BUSY
E = 0;
_nop_(); _nop_();_nop_();
}
/********************************************************/
/*根据设定的坐标数据,定位LCM上的下一个操作单元位置 */
/********************************************************/
void Locatexy(void)
{
unsigned char x,y;
switch (Col&0xc0) /* col.and.0xC0 */
{ /*条件分支执行 */
case 0: {BusyL();break;}/*左区 */
case 0x40: {BusyM();break;}/*中区 */
case 0x80: {BusyR();break;}/*右区 */
}
x = Col&0x3F|0x40; /* col.and.0x3f.or.Set Y Address*/
y = Page&0x07|0xB8; /* row.and.0x07.or.set Page */
wtcom(); /* waitting for enable */
RS = 0; //指令
RW = 0; //写
P1 = y; //设置页面地址
E = 1;
_nop_();
E = 0;
_nop_(); _nop_();_nop_();_nop_();
wtcom(); /* waitting for enable */
RS = 0;
RW = 0;
P1 = x; //设置列地址
E = 1;
_nop_();_nop_();_nop_();_nop_();
E = 0;
_nop_(); _nop_();_nop_();_nop_();
}
/***************************/
/*写指令 */
/***************************/
void WriteCommandL( unsigned char CommandByte )
{
BusyL();
P1 = CommandByte;
RS = 0; //指令
RW = 0;
E = 1;
_nop_();_nop_();_nop_();_nop_();
E = 0;
_nop_();_nop_();_nop_();_nop_();
}
void WriteCommandM( unsigned char CommandByte )
{
BusyM();
P1 = CommandByte;
RS = 0; //指令
RW = 0;
E = 1;
_nop_();_nop_();_nop_();_nop_();
E = 0;
_nop_();_nop_();_nop_();_nop_();
}
void WriteCommandR( unsigned char CommandByte )
{
BusyR();
P1 = CommandByte;