` 一、评估板使用说明 1. 功能
注:可实现的功能 a.可以显示预先存入屏幕内的图片广告信息
2. 需使用的工具 a.硬件:MSP430F149最小系统,ESP8266模块。 b. 软件: IAR。 c.原理图:详见“硬件原理图”文件夹。 d.程序: 430程序在“MSP430F149程序”文件夹。
二、评估板硬件和软件部分详细介绍
1.硬件部分
(1)硬件接口定义
功能
| 对应MSP430F149的IO
|
| TXD(屏端子显示)
| P34 | | RXD(屏端子显示)
| P35 | | Esp8266串口
| P36->RXT,P37->TXD
| |
|
|
|
2. 软件程序
(1)界面设置在“DWIN_SET”文件夹中。STM32程序在“MSP430F149程序”文件夹中。 操作过程:将app工程文件夹下的apk文件安装到安卓手机;将手机wifi连接上ESP8266的热点“电子便签”。
(2)MCU程序
main.c
- [size=4][size=4]#include
- #include
- #include
- #include "dwin.h"
- #define CPU_CLK 8000000 //系统时钟8M
- #define CPU_F ((double)8000000)
- #define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
- #define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
- void Delays(void);
- void PutString(char *ptr);
- void UART0_Init(unsigned long baud)
- {
- u16 baudset;
- baudset=(u16)(CPU_CLK/baud);
-
- P3SEL |= BIT4 + BIT5; // P3.4,5 = USART0 TXD/RXD
- ME1 |= UTXE0 + URXE0; // 使能UART0的TXD和RXD
- UCTL0 |= CHAR; // 数据位为8bit
- UTCTL0 |= SSEL1; // 选择时钟源,SSEL0 32.768KHZ SSEL1 8M
- UBR00 = (u8)(baudset); // 初值整数部分低8位
- UBR10 = (u8)(baudset>>8); // 初值整数部分高8位
- UMCTL0 =(u8)((baudset-U0BR0)*8); //初值小数部分
- UCTL0 &= ~SWRST; // Initialize USART state machine
- IE1 |= URXIE0; // 使能UART0的RX中断
- _EINT(); // 打开全局中断控制位
- }
- void Init_CLK(void)
- {
- unsigned int qq;
- WDTCTL= WDTPW + WDTHOLD ; // 关看门狗
- BCSCTL1 &= ~XT2OFF; //打开XT2高速晶体振荡器
- do
- {
- IFG1 &= ~OFIFG; // 清除振荡器失效标志
- for(qq=0xff;qq>0;qq--); //延时,等待XT2起振
- }
- while((IFG1&OFIFG)); //判断XT2是否起振
- BCSCTL2 |= SELM_2; //MCLK=XT2
- //BCSCTL2 |= DIVM_0; //控制MCLK不分频,默认
- BCSCTL2 |= SELS; //SMCLK=XT2
- //BCSCTL2 |= DIVS_0; //控制SMCLK不分频,默认
- }
- /**************************************************************
- *函数功能:初始化UART1
- *P3.6 TXD P3.7 RXD
- ***************************************************************/
- void UART1_Init(unsigned long baud)
- {
- u16 baudset;
- baudset=(u16)(CPU_CLK/baud);
-
- P3SEL |= BIT6 + BIT7; // P3.6,7 = USART0 TXD/RXD
- ME2 |= UTXE1 + URXE1; // 使能UART1的TXD和RXD
- UCTL1 |= CHAR; // 数据位为8bit
- UTCTL1 |= SSEL1; // 选择时钟源,SSEL0 32.768KHZ SSEL1 8M
- UBR01 = (u8)(baudset); // 初值整数部分低8位
- UBR11 = (u8)(baudset>>8); // 初值整数部分高8位
- UMCTL1 =(u8)((baudset-U0BR0)*8); //初值小数部分
- UCTL1 &= ~SWRST; // Initialize USART state machine
- IE2 |= URXIE1; // 使能UART1的RX中断
- _EINT(); // 打开全局中断控制位
- }
- /**************************************************************
- 函数功能:从UART1发送一个字符
- 输入参数:Byte -- 要发送的字符
- ***************************************************************/
- void UART1_SendChar(u8 Byte)
- {
- while (!(IFG2 & UTXIFG1));
- TXBUF1 = Byte; // 将要发送的字符送到数据寄存器
- }
- /**************************************************************
- 函数功能:发送字符串函数
- 输入参数: s 要发送的字符串
- **************************************************************/
- void UART1_Send_Str(char *s)
- {
- while (*s)
- {
- UART1_SendChar(*s);
- s++;
- }
- }
- void esp_8266_init()
- {
- #define usart2_send_string UART1_Send_Str
- usart2_send_string("AT+RST
- ");
- delay_ms(2200);
- usart2_send_string("AT+CWMODE=3
- ");
- delay_ms(2200);
- usart2_send_string("AT+CWSAP="电子便签","66666666",11,0
- ");
- delay_ms(2200);
- usart2_send_string("AT+CIPSTART="UDP","255.255.255.255",9001,9005,0
- ");
- delay_ms(2200);
- usart2_send_string("AT+CIPMODE=1
- ");
- delay_ms(2200);
- usart2_send_string("AT+CIPSEND
- ");
-
- }
- /********************主函数**********************/
- int p_n=1;
- void main(void)
- {
-
- /*下面六行程序关闭所有的IO口*/
- P1DIR = 0XFF;P1OUT = 0XFF;
- P2DIR = 0XFF;P2OUT = 0XFF;
- P3DIR = 0XFF;P3OUT = 0XFF;
- P4DIR = 0XFF;P4OUT = 0XFF;
- P5DIR = 0XFF;P5OUT = 0XFF;
- P6DIR = 0XFF;P6OUT = 0XFF;
-
- WDTCTL = WDTPW + WDTHOLD; // 关狗
- Init_CLK();
- P6DIR |= BIT2;P6OUT |= BIT2; // 关电平转换
- UART0_Init(115200);
- UART1_Init(115200);
- LCD_printf(0x04,0xfFFF,0xf00f,200-72,50,"自动浇花系统");
- esp_8266_init();
- while(1)
- {
- pic(p_n);
- }
- }
- //串口1中断函数
- #pragma vector=UART1RX_VECTOR
- __interrupt void UART1_RX_ISR(void)
- {
- u8 c;
- IFG2&=~URXIFG1;
- c = RXBUF1; // 接收到数据了
- if(c!=0)p_n=c;
-
- }
- [/size][/size]
复制代码
dwin.h
- [size=4][size=4]#ifndef _DWIN
- #define _DWIN
- #include
- #include
- #include
- typedef unsigned char u8;
- typedef unsigned int u16;
- /*******************************************
- 函数名称:PutSting
- 功 能:向PC机发送字符串
- 参 数:无
- 返回值 :无
- ********************************************/
- void PrintString1(char *ptr)
- {
- while(*ptr != '\0')
- {
- while (!(IFG1 & UTXIFG0)); // TX缓存空闲?
- TXBUF0 = *ptr++; // 发送数据
- }
- }
- char tmp[100];
- /****************显示字符串函数*****************/
- /*参数:mode:D7********************************/
- void TX1_write2buff(char txh)
- {
- while (!(IFG1 & UTXIFG0)); // TX缓存空闲?
- TXBUF0 = txh; // 发送数据
- }
- void LCD_printf(u8 mode,u16 Color,u16 Bcolor,u16 x,u16 y,const char *format, ...)
- {
-
- va_list arg;
- va_start(arg, format);
- vsprintf(tmp,format,arg);
- va_end(arg);
- TX1_write2buff(0xaa);
-
- TX1_write2buff(0x11);
- TX1_write2buff(mode);//模式
- TX1_write2buff(Color/256);
- TX1_write2buff(Color%256);//前景颜色
- TX1_write2buff(Bcolor/256);
- TX1_write2buff(Bcolor%256);//背景颜色
- TX1_write2buff(x/256);
- TX1_write2buff(x%256);//横坐标
- TX1_write2buff(y/256);
- TX1_write2buff(y%256);//Y坐标
-
- PrintString1(tmp);
- TX1_write2buff(0xcc);
- TX1_write2buff(0x33);
- TX1_write2buff(0xc3);
- TX1_write2buff(0x3c);
- }
- /****************显示二维码函数*****************/
- /*参数:mode:D7********************************/
- void erweima(u16 x,u16 y,u8 QR_Pixel,const char *format, ...)
- {
- va_list arg;
- va_start(arg, format);
- vsprintf(tmp,format,arg);
- va_end(arg);
-
- TX1_write2buff(0xaa);
-
- TX1_write2buff(0x21);
- TX1_write2buff(x/256);
- TX1_write2buff(x%256);//横坐标
- TX1_write2buff(y/256);
- TX1_write2buff(y%256);//Y坐标
- TX1_write2buff(QR_Pixel);//二维码每个点的大小
-
- PrintString1(tmp);
- TX1_write2buff(0xcc);
- TX1_write2buff(0x33);
- TX1_write2buff(0xc3);
- TX1_write2buff(0x3c);
- }
- /****************绘图清屏函数*****************/
- /*参数:mode:D7********************************/
- void clr(u16 Color)
- {
- TX1_write2buff(0xaa);
-
- TX1_write2buff(0x01);
- TX1_write2buff(Color/256);
- TX1_write2buff(Color%256);//颜色
-
- TX1_write2buff(0xcc);
- TX1_write2buff(0x33);
- TX1_write2buff(0xc3);
- TX1_write2buff(0x3c);
- }
- /****************绘图直线插入函数*****************/
- /*参数:mode:D7********************************/
- void Linear_interpolation(u8 num,u16 Color,...)
- {
- va_list arg_ptr;
- int tempValue;
- num*=2;
- TX1_write2buff(0xaa);
- TX1_write2buff(0x03);
- TX1_write2buff(Color/256);
- TX1_write2buff(Color%256);
- va_start(arg_ptr,Color);
- while(num--)
- {
- tempValue=va_arg(arg_ptr,int);
- TX1_write2buff(tempValue/256);
- TX1_write2buff(tempValue%256);
- }
- va_end(arg_ptr);
- TX1_write2buff(0xcc);
- TX1_write2buff(0x33);
- TX1_write2buff(0xc3);
- TX1_write2buff(0x3c);
- }
- /****************绘图打点插入函数*****************/
- /*参数:mode:D7********************************/
- void Place_point(u8 num,u16 Color,u16 nx,u16 ny,...)
- {
- va_list arg_ptr;
- int tempValue;
- num*=2;
- TX1_write2buff(0xaa);
- TX1_write2buff(0x02);
- TX1_write2buff(Color/256);
- TX1_write2buff(Color%256);
- TX1_write2buff(nx%256);
- TX1_write2buff(ny%256);
- va_start(arg_ptr,ny);
- while(num--)
- {
- tempValue=va_arg(arg_ptr,int);
- TX1_write2buff(tempValue/256);
- TX1_write2buff(tempValue%256);
- }
- va_end(arg_ptr);
- TX1_write2buff(0xcc);
- TX1_write2buff(0x33);
- TX1_write2buff(0xc3);
- TX1_write2buff(0x3c);
- }
- /****************屏幕背光亮度设置*****************/
- /*参数:mode:D7********************************/
- void DIM_Set(u8 Set)
- {
- TX1_write2buff(0xaa);
- TX1_write2buff(0x30);
- TX1_write2buff(Set);
- TX1_write2buff(0xcc);
- TX1_write2buff(0x33);
- TX1_write2buff(0xc3);
- TX1_write2buff(0x3c);
- }
- /****************设置扩展串口波特率**************/
- /*参数:mode:D7********************************/
- void Bode_Set(u16 Set)//调节扩展串口波特率
- {
- TX1_write2buff(0xaa);
- TX1_write2buff(0x38);
- TX1_write2buff(15667200/Set/256);
- TX1_write2buff(15667200/Set%256);
- TX1_write2buff(0xcc);
- TX1_write2buff(0x33);
- TX1_write2buff(0xc3);
- TX1_write2buff(0x3c);
- }
- /****************从扩展串口发送字符串**************/
- /*参数:mode:D7********************************/
- void UART_TX(const char *format, ...)//串口发送字符串
- {
- va_list arg;
- va_start(arg, format);
- vsprintf(tmp,format,arg);
- va_end(arg);
- TX1_write2buff(0xaa);
- TX1_write2buff(0x39);
- PrintString1(tmp);
- TX1_write2buff(0xcc);
- TX1_write2buff(0x33);
- TX1_write2buff(0xc3);
- TX1_write2buff(0x3c);
- }
- /****************显示ICO图标**************/
- /*参数:mode:D7********************************/
- void dis_ico(u16 x,u16 y,u8 mode,u8 ids)//显示ico图标
- {
- TX1_write2buff(0xaa);
- TX1_write2buff(0x23);
- TX1_write2buff(x/256);
- TX1_write2buff(x%256);
- TX1_write2buff(y/256);
- TX1_write2buff(y%256);
- TX1_write2buff(y%256);
- TX1_write2buff(mode);
- TX1_write2buff(ids);
- TX1_write2buff(0xcc);
- TX1_write2buff(0x33);
- TX1_write2buff(0xc3);
- TX1_write2buff(0x3c);
- }
- /****************设置动态图标*******************/
- /*参数:mode:D7********************************/
- void disd_ico(u16 x,u16 y,u8 mode,u8 Icon_lib,u8 Icon_IDs,u8 Icon_0IDe,u8 Delay_time)//显示ico图标
- {
- TX1_write2buff(0xaa);
- TX1_write2buff(0x28);
- TX1_write2buff(x/256);
- TX1_write2buff(x%256);
- TX1_write2buff(y/256);
- TX1_write2buff(y%256);
- TX1_write2buff(y%256);
- TX1_write2buff(mode);
- TX1_write2buff(Icon_lib);
- TX1_write2buff(Icon_IDs);
- TX1_write2buff(Icon_0IDe);
- TX1_write2buff(Delay_time);
- TX1_write2buff(0xcc);
- TX1_write2buff(0x33);
- TX1_write2buff(0xc3);
- TX1_write2buff(0x3c);
- }
- /****************设置动态图标*******************/
- /*参数:mode:D7********************************/
- void disc_ico(u16 set)//控制ico动态图标
- {
- TX1_write2buff(0xaa);
- TX1_write2buff(0x29);
-
- TX1_write2buff(set/256);
- TX1_write2buff(set%256);
- TX1_write2buff(0xcc);
- TX1_write2buff(0x33);
- TX1_write2buff(0xc3);
- TX1_write2buff(0x3c);
- }
- /****************写存储器***********************/
- /*参数:mode:D7********************************/
- void writ_sram_flsh(u16 Length,u8 Type,u16 Address)//写数据存储器
- {
- TX1_write2buff(0xaa);
- TX1_write2buff(0x31);
- TX1_write2buff(Type);
- TX1_write2buff(Address/256);
- TX1_write2buff(Address%256);
- while(Length--)
- {
- TX1_write2buff(Address++);
- }
- TX1_write2buff(0xcc);
- TX1_write2buff(0x33);
- TX1_write2buff(0xc3);
- TX1_write2buff(0x3c);
- }
- /****************读存储器***********************/
- /*参数:mode:D7********************************/
- void read_sram_flsh(u16 Length,u8 Type,u16 Address)//写数据存储器
- {
- TX1_write2buff(0xaa);
- TX1_write2buff(0x32);
- TX1_write2buff(Type);
- TX1_write2buff(Address/256);
- TX1_write2buff(Address%256);
- TX1_write2buff(Length);
- TX1_write2buff(0xcc);
- TX1_write2buff(0x33);
- TX1_write2buff(0xc3);
- TX1_write2buff(0x3c);
- }
- void pic(u8 id)
- {
- TX1_write2buff(0xaa);
- TX1_write2buff(0x22);
- TX1_write2buff(0x00);
- TX1_write2buff(id);
- TX1_write2buff(0xcc);
- TX1_write2buff(0x33);
- TX1_write2buff(0xc3);
- TX1_write2buff(0x3c);
- }
- #endif[/size][/size]
复制代码
`
|