完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我用MSP430G2553驱动MzLH04,但是屏幕显示的是不规则的小黑点,有时又显示正确的,但是很不稳定,我试着换了几个屏幕和不同的线,都没有用,应该是主函数定义的不对,函数调用都是现成的程序应该没问题,付下程序,望解答
//****************************************************************************** // MSP430G2xx3 Demo - USCI_A0, SPI 3-Wire Master Incremented Data // // Description: SPI master talks to SPI slave using 3-wire mode. Incrementing // data is sent by the master starting at 0x01. Received data is expected to // be same as the previous transmission. USCI RX ISR is used to handle // communication with the CPU, normally in LPM0. If high, P1.0 indicates // valid data reception. // ACLK = n/a, MCLK = SMCLK = DCO ~1.2MHz, BRCLK = SMCLK/2 // // Use with SPI Slave Data Echo code example. If slave is in debug mode, P3.6 // slave reset signal conflicts with slave's JTAG; to work around, use IAR's // "Release JTAG on Go" on slave device. If breakpoints are set in // slave RX ISR, master must stopped also to avoid overrunning slave // RXBUF. // // MSP430G2xx3 // ----------------- // /|| XIN|- // | | | // --|RST XOUT|- // | | // | P1.2|-> Data Out (UCA0SIMO) // | | // LED(CS) <-|P1.0 P1.1|<- Data In (UCA0SOMI) // | | // RST <-|P1.5 P1.4|-> Serial Clock Out (UCA0CLK) // // // D. Dang // Texas Instruments Inc. // February 2011 // Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10 //x 0~127 y 0~63 原点在左上角 //****************************************************************************** #include "msp430g2553.h" unsigned char MST_Data, SLV_Data; unsigned char X_Witch=6; unsigned char Y_Witch=10; unsigned char X_Witch_cn=16; unsigned char Y_Witch_cn=16; unsigned char Dis_Zero=0; #define Dis_X_MAX 128-1 #define Dis_Y_MAX 64-1 //#define HEHE B0C1 void Send(unsigned char data) { //P1OUT&=~0x01;//cs=0 // __delay_cycles(50); perhaps UCA0TXBUF=data; //P1OUT|=0x01;//cs=1 } void ClrScreen(void) { //清屏操作 P1OUT&=~0x01;//cs=0 Send(0x80); //送指令0x80 P1OUT|=0x01;//cs=1 } //======================================================================== //设置背景亮度//Grade 0~127 //======================================================================== void SetBackLight(unsigned char Deg) { P1OUT&=~0x01;//cs=0 Send(0x8a); Send(Deg); P1OUT|=0x01;//cs=1 } //======================================================================== //画直线 //======================================================================== void Line(unsigned char s_x,unsigned char s_y,unsigned char e_x,unsigned char e_y) { P1OUT&=~0x01;//cs=0 Send(0x02);//送指令0x02 Send(s_x);//起点X轴坐标 Send(s_y);//起点Y轴坐标 Send(e_x);//终点X轴坐标 Send(e_y);//终点Y轴坐标 P1OUT|=0x01;//cs=1 } //======================================================================== // 函数: void Circle(unsigned char x,unsigned char y, // unsigned char r,unsigned char mode) // 描述: 以x,y为圆心R为半径画一个圆(mode = 0) or 圆面(mode = 1) // 参数: // 返回: 无 // 备注: 画圆函数执行较慢,如果MCU有看门狗,请作好清狗的操作 // 版本: // 2007/07/19 First version //======================================================================== void Circle(unsigned char x,unsigned char y,unsigned char r,unsigned char mode) { P1OUT&=~0x01;//cs=0 if(mode) Send(0x06); else Send(0x05); Send(x); Send(y); Send(r); P1OUT|=0x01;//cs=1 } //======================================================================== // 函数: void FontSet(unsigned char Font_NUM,unsigned char Color) // 描述: ASCII字符字体设置 // 参数: Font_NUM 字体选择,以驱动所带的字库为准 // Color 文本颜色,仅作用于ASCII字库 // 返回: 无 // 备注: // 版本: // 2007/07/19 First version //======================================================================== void FontSet(unsigned char Font_NUM,unsigned char Color) { unsigned char ucTemp=0; if(Font_NUM==0) { X_Witch = 6;//7; Y_Witch = 10; } else { X_Witch = 8; Y_Witch = 16; } ucTemp = (Font_NUM<<4)|Color; //设置ASCII字符的字型 P1OUT&=~0x01;//cs=0 Send(0x81); //传送指令0x81 Send(ucTemp); //选择8X16的ASCII字体,字符色为黑色 P1OUT|=0x01;//cs=1 //完成操作置SS高电平 } //======================================================================== // 函数: void FontMode(unsigned char Cover,unsigned char Color) // 描述: 设置字符显示覆盖模式 // 参数: Cover 字符覆盖模式设置,0或1 // Color 覆盖模式为1时字符显示时的背景覆盖色 // 返回: 无 // 备注: // 版本: // 2008/11/27 First version //======================================================================== void FontMode(unsigned char Cover,unsigned char Color) { unsigned char ucTemp=0; ucTemp = (Cover<<4)|Color; //设置ASCII字符的字型 P1OUT&=~0x01;//cs=0 Send(0x89); //传送指令0x81 Send(ucTemp); //选择8X16的ASCII字体,字符色为黑色 P1OUT|=0x01;//cs=1 } //======================================================================== // 函数: void PutChar(unsigned char x,unsigned char y,unsigned char a) // 描述: 写入一个标准ASCII字符 // 参数: x X轴坐标 y Y轴坐标 // a 要显示的字符在字库中的偏移量 // 返回: 无 // 备注: ASCII字符可直接输入ASCII码即可 // 版本: // 2007/07/19 First version //======================================================================== void PutChar(unsigned char x,unsigned char y,unsigned char a) { //显示ASCII字符 P1OUT&=~0x01;//cs=0 Send(0x07); //传送指令0x07 Send(x); //要显示字符的左上角的X轴位置 Send(y); //要显示字符的左上角的Y轴位置 Send(a); //要显示字符ASCII字符的ASCII码值 P1OUT|=0x01;//cs=1 } //======================================================================== // 函数: void FontSet_cn(unsigned char Font_NUM,unsigned char Color) // 描述: 汉字库字符字体设置 // 参数: Font_NUM 字体选择,以驱动所带的字库为准 // Color 文本颜色,仅作用于汉字库 // 返回: 无 // 备注: // 版本: // 2007/07/19 First version //======================================================================== void FontSet_cn(unsigned char Font_NUM,unsigned char Color) { unsigned char ucTemp=0; if(Font_NUM==0) { X_Witch_cn = 12; Y_Witch_cn = 12; } else { X_Witch_cn = 16; Y_Witch_cn = 16; } ucTemp = (Font_NUM<<4)|Color; //设置ASCII字符的字型 P1OUT&=~0x01;//cs=0 Send(0x82); //传送指令0x82 Send(ucTemp); //选择16X16的字体,字符色为黑色 P1OUT|=0x01;//cs=1 } //======================================================================== // 函数: void PutChar_cn(unsigned char x,unsigned char y,unsigned short * GB) // 描述: 写入一个二级汉字库汉字 // 参数: x X轴坐标 y Y轴坐标 // a GB码 // 返回: 无 // 备注: // 版本: // 2007/07/19 First version // 2007/07/24 V1.2 for MCS51 Keil C //======================================================================== void PutChar_cn(unsigned char x,unsigned char y,unsigned char * GB) { //显示ASCII字符 P1OUT&=~0x01;//cs=0 Send(0x08); //传送指令0x08 Send(x); //要显示字符的左上角的X轴位置 Send(y); //要显示字符的左上角的Y轴位置 Send(*(GB++)); //传送二级字库中汉字GB码的高八位值 Send(*GB); //传送二级字库中汉字GB码的低八位值 P1OUT|=0x01;//cs=1 } //======================================================================== // 函数: void PutString_cn(unsigned char x,unsigned char y,unsigned short *p) // 描述: 在x、y为起始坐标处写入一串汉字字符 // 参数: x X轴坐标 y Y轴坐标 // p 要显示的字符串 // 返回: 无 // 备注: 同PutChar_cn中的解释 // 版本: // 2007/07/19 First version // 2007/07/24 V1.2 for MCS51 Keil C //======================================================================== void PutString_cn(unsigned char x,unsigned char y,unsigned char *p) { while(*p!=0) { if(*p<128) { PutChar(x,y,*p); x += X_Witch+1; if((x/* + X_Witch*/) > Dis_X_MAX) { x = Dis_Zero; if((Dis_Y_MAX - y) < Y_Witch) break; else y += Y_Witch_cn; } p+=1; } else { PutChar_cn(x,y,p); x += X_Witch_cn+1; if((x/* + X_Witch_cn*/) > Dis_X_MAX) { x = Dis_Zero; if((Dis_Y_MAX - y) < Y_Witch_cn) break; else y += Y_Witch_cn; } p+=2; } } } main() { volatile unsigned int i; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1OUT = 0x00; // P1 setup for LED & reset output P1DIR |= BIT0 + BIT5; // P1SEL =BIT2 + BIT4; P1SEL2 =BIT2 + BIT4; UCA0CTL0 |= UCCKPL + UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 |= 0x02; // /2 UCA0BR1 = 0; // UCA0MCTL = 0; // No modulation UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt P1OUT &= ~BIT5; // Now with SPI signals initialized, __delay_cycles(75); P1OUT |= BIT5; // reset slave __delay_cycles(75); // Wait for slave to initialize //UCA0TXBUF = (0x80); P1OUT&=~0x01;//cs=0 //Send(0x80); SetBackLight(4); /*ClrScreen();*/ FontSet_cn(1,1); //FontMode(0,1); PutChar_cn(10,33,"显"); PutString_cn(40,33,"铭正同创"); FontSet_cn(0,1); PutChar_cn(10,50,"显"); PutString_cn(40,50,"汉字库液晶"); //Circle(33,44,10,0); //Line(30,11,30,60); //SetBackLight(100); //设置背光打开 while(1) {} } |
|
相关推荐
2 个讨论
|
|
还是不行啊
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 07:41 , Processed in 0.650735 second(s), Total 53, Slave 41 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号