头文件和12864相关配置
#include <msp430f5529.h>
#include <msp430.h>
#include "stdint.h"
#define uint unsigned int
#define uchar unsigned char
#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))
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
/*12864应用指令*/
#define CLEAR_SCREEN 0x01 //清屏指令:清屏且AC值为00H
#define AC_INIT 0x02 //将AC设置为00H。且游标移到原点位置
#define CURSE_ADD 0x06 //设定游标移到方向及图像整体移动方向(默认游标右移,图像整体不动)
#define FUN_MODE 0x30 //工作模式:8位基本指令集
#define DISPLAY_ON 0x0c //显示开,显示游标,且游标位置反白
#define DISPLAY_OFF 0x08 //显示关
#define CURSE_DIR 0x14 //游标向右移动:AC=AC+1
#define SET_CG_AC 0x40 //设置AC,范围为:00H~3FH
#define SET_DD_AC 0x80
#define P10 0
#define P11 1
#define P12 2
#define P13 3
#define P14 4
#define P15 5
#define P16 6
#define P17 7
#define RS_CLR P6OUT &= ~(1 << P14) //RS置低
#define RS_SET P6OUT |= (1 << P14) //RS置高
#define RW_CLR P6OUT &= ~(1 << P10) //RW置低
#define RW_SET P6OUT |= (1 << P10) //RW置高
#define EN_CLR P6OUT &= ~(1 << P11) //E置低
#define EN_SET P6OUT |= (1 << P11) //E置高
#define PSB_CLR P6OUT &= ~(1 << P12) //PSB置低,串口方式
#define PSB_SET P6OUT |= (1 << P12) //PSB置高,并口方式
#define RST_CLR P6OUT &= ~(1 << P13) //RST置低
#define RST_SET P6OUT |= (1 << P13) //RST置高
#define DataPort P3OUT //P4口为数据口
uint16_t freq = 0;
uint8_t printflag = 0;
uchar lcd_buf[6]={0,0,0,0,0,0};
char a1 = 0;
void WDT_Init()
{
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗
}
//*************************************************************************
// 初始化IO口子程序
//*************************************************************************
void Port_init()
{
P3SEL = 0x00;
P3DIR = 0xFF;
P6SEL = 0x00;
P6DIR|= BIT0 + BIT1 + BIT2 + BIT3 + BIT4;
PSB_SET; //液晶并口方式
RST_SET; //复位脚RST置高
}
//***********************************************************************
// 显示屏命令写入函数
//***********************************************************************
void LCD_write_com(unsigned char com)
{
RS_CLR;
RW_CLR;
EN_SET;
DataPort = com;
delay_ms(5);
EN_CLR;
}
//***********************************************************************
// 显示屏数据写入函数
//***********************************************************************
void LCD_write_data(unsigned char data)
{
RS_SET;
RW_CLR;
EN_SET;
DataPort = data;
delay_ms(5);
EN_CLR;
}
//***********************************************************************
// 显示屏清空显示
//***********************************************************************
void LCD_clear(void)
{
LCD_write_com(0x01);
delay_ms(5);
}
//***********************************************************************
// 显示屏字符串写入函数
//***********************************************************************
void LCD_write_str(unsigned char x,unsigned char y,unsigned char *s)
{
if (y == 0)
{
LCD_write_com(0x83 + x); //第一行显示
}
if(y == 1)
{
LCD_write_com(0x90 + x); //第二行显示
}
if (y == 2)
{
LCD_write_com(0x88 + x); //第三行显示
}
if(y == 3)
{
LCD_write_com(0x98 + x); //第四行显示
}
delay_ms(10);
while (*s)
{
LCD_write_data( *s);
delay_ms(5);
s ++;
}
}
void LCD_init(void)
{
LCD_write_com(FUN_MODE); //显示模式设置
delay_ms(5);
LCD_write_com(FUN_MODE); //显示模式设置
delay_ms(5);
LCD_write_com(DISPLAY_ON); //显示开
delay_ms(5);
LCD_write_com(CLEAR_SCREEN); //清屏
delay_ms(5);
}
|