|
本来看到坛里有写1602,想换个其他的,但暂时没找到可用的外设,就只好先用这个1602折腾着,顺便发发自己的心得 PSOC使用的确是比较方便,不过刚拿到板准备玩时确发生了一些小问题,发现我的电脑安装驱动后出现的串口是一个问号,重装驱动,下载软件,搞了半天也没有搞定,后来无意中看到有人提到可能是系统问题,从网上下载了个DLL文件,放到系统目录下,终于搞定,所以如果使用GHOST 装机的要注意了,有可能发生这样的问题。 言归正传,以前玩过 Arduino ,刚好手头有个Arduio上使用的1602,又看到PSOC开发板支持Arduino,就打算利用起来,先在TopDesign中将要是用的资源拖进来 使用资源包含: Control Reg Digital Output Pin(LED ,RS ,E,D4,D5,D6,D7)lcd_rs,lcd_e,LED1 选择相同配置,如下图,记住不用选择HW Connection ,否则会报错还需要配置1602使用的数据端口,其他配置不变,但需要选中HW Connection,为了看起来好看一点,在Maping选项卡中选择Display as bus。接下来需要配置Control Reg ,选择为4路,其他不变。接下来就要写程序了,从网上找个1602 四线驱动的程序稍作修改,就可以直接使用,对于操作数据端口,就直接当成一个整体赋值, //1602.c/* ======================================== * * Copyright YOUR COMPANY, THE YEAR * All Rights Reserved * UNPUBLISHED, LICENSED SOFTWARE. * * CONFIDENTIAL AND PROPRIETARY INFORMATION * WHICH IS THE PROPERTY OF your company. * * ========================================* /// rs 8// e 9// 4 -5 -6 -7//** 10 blacklight ctl #include <device.h> void lcd_en(void) { lcd_e_Write(0x01); CyDelayUs(10); lcd_e_Write(0x0); } void lcd_cmd(unsigned char cmd) { CyDelayUs(40); lcd_rs_Write(0); LCD_DATA_Write(0); LCD_DATA_Write(cmd>>4); lcd_en(); LCD_DATA_Write(0); LCD_DATA_Write(cmd); lcd_en(); } void lcd_dat(unsigned char dat) { CyDelayUs(40); lcd_rs_Write(1); LCD_DATA_Write(0); LCD_DATA_Write(dat>>4); lcd_en(); LCD_DATA_Write(0); LCD_DATA_Write(dat); lcd_en();} void lcd_clr(void) { lcd_cmd(0x01); CyDelayUs(1700); } void lcd_pos (unsigned char x, unsigned char y) { if(y) lcd_cmd(x | 0xc0); else lcd_cmd(x | 0x80); } void lcd_printc (unsigned char x, unsigned char y, unsigned char c) { lcd_pos(x, y); CyDelayUs(1000); lcd_dat(c); CyDelayUs(1000); }/*--------------------------------------------------------------*/ void lcd_prints (unsigned char x, unsigned char y, unsigned char *s) { lcd_pos(x, y); while(*s) { lcd_dat(*s); s++; } } void Init_LCD(void) { lcd_cmd(0x28); lcd_en(); lcd_cmd(0x28); lcd_cmd(0x0c); lcd_cmd(0x01); CyDelayUs(1700); }/* [] END OF FILE *.. //main.c #include extern void Init_LCD(void); extern void lcd_prints (unsigned char x, unsigned char y, unsigned char *s); void main() { /* Place your initialization/startup code here (e.g. MyInst_Start()) */ Init_LCD(); lcd_prints(0,0,"hello eeworld"); /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */ for(;;) { CyDelay(1000); LED1_Write(1); CyDelay(1000); LED1_Write(0); /* Place your application code here. */ } }驱动显示 效果
[ 本帖最后由 penny2799 于 2013-11-12 23:56 编辑 ]
|
|