頭文件和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);
}
|