本帖最后由 STM32不完全手册 于 2012-11-27 15:44 编辑
今天弄到了了一块JM12864M,老师说是N年前花100多买的
,绝对好用
结果在网上DOWN了一段代码更改了一下...一小天了,还没驱动起来,对照了数据手册,也没找到哪里不对劲...
我的两份原厂的参考资料........
和一张12864靓照.......谢谢万能的坛友帮忙,求点播
IMG_20121127_153150.jpg (1.81 MB, 下载次数: 0)
下载附件
2012-11-27 15:42 上传
#include "reg52.h"
#include "intrins.h"
sbit RS = P1^0 ;
sbit RW = P1^1 ;
sbit CS = P1^2 ;
#define io_LCD12864_DATAPORT P3
#define SET_DATA RS = 1 ;
#define CLR_INC RS = 0 ;
#define SET_READ RW = 1 ;
#define CLR_WRITE RW = 0 ;
#define SET_EN CS = 1 ;
#define CLR_EN CS = 0 ;
void v_Lcd12864PutString_f( unsigned char x, unsigned char y, unsigned char *pData );
void v_Lcd12864CheckBusy_f( void ) ;
void v_Lcd12864SendData_f( unsigned char byData ) ;
void v_Lcd12864SendCmd_f( unsigned char byCmd ) ;
void v_DelayMs_f( unsigned int nDelay ) ;
void v_Lcd12864Init_f( void ) ;
void v_Lcd12864SetAddress_f( unsigned char x, y ) ;
void delay( unsigned int nDelay ) ;
void main( void )
{
v_Lcd12864Init_f() ;
v_Lcd12864PutString_f( 0,1, "★☆12864") ;
while( 1 ) ;
}
void v_Lcd12864PutString_f( unsigned char x, unsigned char y, unsigned char *pData )
{
v_Lcd12864SetAddress_f( x, y ) ;
while( *pData != ' ' )
{
v_Lcd12864SendData_f( *pData++ ) ;
}
}
void v_Lcd12864CheckBusy_f( void )
{
unsigned int nTimeOut = 0 ;
CLR_INC
SET_READ
CLR_EN
SET_EN
while( ( io_LCD12864_DATAPORT & 0x80 ) && ( ++nTimeOut != 0 ) ) ;
CLR_EN
CLR_INC
SET_READ
}
void v_Lcd12864SendCmd_f( unsigned char byCmd )
{
v_Lcd12864CheckBusy_f() ;
CLR_INC
CLR_WRITE
SET_EN
io_LCD12864_DATAPORT = byCmd ;
CLR_EN
}
void v_Lcd12864SendData_f( unsigned char byData )
{
v_Lcd12864CheckBusy_f() ;
SET_DATA
CLR_WRITE
SET_EN
io_LCD12864_DATAPORT = byData ;
CLR_EN
}
void delay( unsigned int nDelay ) //89us
{
unsigned int i ;
for( ; nDelay > 0 ; nDelay-- )
{
for( i = 9 ; i > 0 ; i-- ) ;
}
}
void v_DelayMs_f( unsigned int nDelay )
{
unsigned int i ;
for( ; nDelay > 0 ; nDelay-- )
{
for( i = 125 ; i > 0 ; i-- ) ;
}
}
void v_Lcd12864Init_f( void ) //初始化
{
v_Lcd12864SendCmd_f(0x30) ;
delay(1);
v_Lcd12864SendCmd_f(0x0c) ;
delay(1);
v_Lcd12864SendCmd_f(0x01);
v_DelayMs_f(6) ;
v_Lcd12864SendCmd_f(0x02);
v_DelayMs_f(6) ;
v_Lcd12864SendCmd_f(0x06);
delay(1);
v_Lcd12864SendCmd_f(0x0c);
delay(1);
}
void v_Lcd12864SetAddress_f( unsigned char x, y )
{
unsigned char byAddress ;
switch( y )
{
case 0 : byAddress = 0x80 + x ;
break;
case 1 : byAddress = 0x90 + x ;
break ;
case 2 : byAddress = 0x88 + x ;
break ;
case 3 : byAddress = 0x98 + x ;
break ;
default :
break ;
}
v_Lcd12864SendCmd_f( byAddress ) ;
}
一周热门 更多>