我买的字符液晶模块fm1602c, 我想问资料中提到的250KHz或者是270KHz频率是液晶模块的处理速度吗?
我说一下我的配置情况,MCU是MC9S08GT60,断口C的3,4,5,6分别作为74HC245的方向控制,RS,RW,E。端口B作为DB线,我的晶振是4MHz,转换成20MHZ的总线频率。
我写了程序,可以帮我看看,为什么不成功吗?
#include <hidef.h> /* for EnableInterrupts macro */ #include <MC9S08GT60.h> /* include peripheral declarations */
#include "main_asm.h" /* interface to the assembly module */
#define CTRLD PTCDD #define CTRL PTCD #define DIR PTCD_PTCD3 #define RS PTCD_PTCD4 #define RW PTCD_PTCD5 #define E PTCD_PTCD6
#define DIRD PTCDD_PTCDD3 #define RSD PTCDD_PTCDD4 #define RWD PTCDD_PTCDD5 #define ED PTCDD_PTCDD6
#define DBD PTBDD #define DB PTBD #define BF PTBD_PTBD7
#define nop asm("nop")
void busy(); //判忙// void w_dat(unsigned char); //写显示数据子程序// void w_com(unsigned char); //写指令代码子程序// void init(void); //初始化子程序// //void disp(unsigned char); //显示// void delay50us(); //延时// void delay2ms(); //延时//
void busy() { unsigned char status; CTRLD=0x78; DBD=0x00; DIR=0; do{ RS=0; RW=1; E=1; status=DB; delay50us(); delay50us(); delay50us(); delay50us(); }while(status&0x80); nop; E=0; RS=1; RW=0; }
void delay2ms() { #asm delay2ms: PSHA LDA #$0C loop1: PSHA LDA #$64 loop2: NOP NOP DBNZA loop2 PULA DBNZA loop1 PULA #endasm }
void delay50us() { #asm delay50us: PSHA LDA #$64 loop: NOP NOP DBNZA loop PULA #endasm }
void w_dat(unsigned char dat) //写数据// { CTRLD=0x78; DBD=0xff; DIR=1; E=1; RS=1; RW=0; DB=dat; delay50us(); delay50us(); nop; E=0; RS=0; RW=1; }
void w_com(unsigned char com) //写指令// { CTRLD=0x78; DBD=0xff; DIR=1; E=1; RS=0; RW=0; DB=com; delay2ms(); nop; E=0; RS=1; RW=1; }
void init(void) { unsigned char i; for (i=0;i<3;i++){ w_com(0x38); delay50us(); delay50us(); busy(); } w_com(0x01); delay2ms(); busy(); w_com(0x02); delay2ms(); busy(); w_com(0x04); delay50us(); delay50us(); busy(); w_com(0x0c); delay50us(); delay50us(); busy(); w_com(0x07); delay50us(); delay50us(); busy(); }
const unsigned char String[12]={0x57,0x45,0x4c,0x43,0x4f,0x4d,0x45,0x20,0x59,0x4f,0x55,0x21};//WELCOME YOU /*void disp(void) { unsigned char i=0; init(); RS=0; RW=0; w_com(0x00); RS=1; RW=0; for(i=0;i<=11;i++) w_dat(String); } */
void main(void) { unsigned char i; SOPT_COPE=0; EnableInterrupts; /* enable interrupts */ /* include your code here */
asm_main(); /* call the assembly function */ init(); w_com(0x40); delay50us(); delay50us(); for(i=0;i<=11;i++) { w_dat(String); delay50us(); delay50us(); } w_com(0x01); delay50us(); delay50us(); for(;;) { __RESET_WATCHDOG(); /* feeds the dog */ //disp();
} /* loop forever */ /* please make sure that you never leave this function */ } |