📄 430初程序3310已调试.txt
字号:
#include <msp430x14x.h>
//#include "3310LCD_function.h"
#include "english_6x8_pixel.h" //英文字库
#include "write_chinese_string_pixel.h" //汉字库
#include "move_chinese_string_pixel.h" //移动汉字库
//*******************************************************************
//定义3310引脚
//***************************************************************
#define LCD_DC 0x08 // LCD第4脚, Msp430:P13 第4脚
#define LCD_CE 0x10 // LCD第5脚, Msp430:P14 第5脚
#define SPI_MOSI 0x20 // LCD第3脚, Msp430:P15(MOSI) 第6脚---SDIN
#define LCD_RST 0x40 // LCD第8脚, Msp430:P16(MISO) 第7脚
#define SPI_CLK 0x80 // LCD第2脚, Msp430:P17(SCK) 第8脚
/*-------------------------------------
定义延时函数
---------------------------------------------*/
#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 LCD_init(void);
void LCD_clear(void);
void LCD_write_english_string(unsigned char X,unsigned char Y,char *s);
void LCD_write_chinese_string(unsigned char X, unsigned char Y,
unsigned char ch_with,unsigned char num,
unsigned char line,unsigned char row);
void LCD_move_chinese_string (unsigned char X, unsigned char Y, unsigned char T);
void LCD_move_chinese_string(unsigned char X, unsigned char Y, unsigned char T);
void LCD_write_char(unsigned char c);
void LCD_draw_bmp_pixel(unsigned char X,unsigned char Y,unsigned char *map,
unsigned char Pix_x,unsigned char Pix_y);
void LCD_write_byte(unsigned char data, unsigned char dc);
//-------------------------------------------------------------
/*-----------------------------------------------------------------------
LCD_init : 3310LCD初始化
编写日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_init(void)
{
P2OUT &= ~LCD_RST; // 产生一个让LCD复位的低电平脉冲
delay_us(1);
P2OUT |= LCD_RST;
P2OUT &= ~LCD_CE ; // 关闭LCD
delay_us(1);
P2OUT |= LCD_CE; // 使能LCD
delay_us(1);
LCD_write_byte(0x21, 0); // 使用扩展命令设置LCD模式
LCD_write_byte(0xc8, 0); // 设置偏置电压
LCD_write_byte(0x06, 0); // 温度校正
LCD_write_byte(0x13, 0); // 1:48
LCD_write_byte(0x20, 0); // 使用基本命令
LCD_clear(); // 清屏
LCD_write_byte(0x0c, 0); // 设定显示模式,正常显示
P2OUT &= ~LCD_CE ; // 关闭LCD
}
/*-----------------------------------------------------------------------
LCD_clear : LCD清屏函数
编写日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_clear(void)
{
unsigned int i;
LCD_write_byte(0x0c, 0);
LCD_write_byte(0x80, 0);
for (i=0; i<504; i++)
LCD_write_byte(0, 1);
}
/*-----------------------------------------------------------------------
LCD_set_XY : 设置LCD坐标函数
输入参数:X :0-83
Y :0-5
编写日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0); // column
LCD_write_byte(0x80 | X, 0); // row
}
/*-----------------------------------------------------------------------
LCD_write_char : 显示英文字符
输入参数:c :显示的字符;
编写日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_write_char(unsigned char c)
{
unsigned char line;
c -= 32;
for (line=0; line<6; line++)
LCD_write_byte(font6x8[c][line], 1);
}
/*-----------------------------------------------------------------------
LCD_write_english_String : 英文字符串显示函数
输入参数:*s :英文字符串指针;
X、Y : 显示字符串的位置,x 0-83 ,y 0-5
编写日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)
{
LCD_set_XY(X,Y);
while (*s)
{
LCD_write_char(*s);
s++;
}
}
/*-----------------------------------------------------------------------
LCD_write_chinese_string: 在LCD上显示汉字
输入参数:X、Y :显示汉字的起始X、Y坐标;
ch_with :汉字点阵的宽度
num :显示汉字的个数;
line :汉字点阵数组中的起始行数
row :汉字显示的行间距
编写日期 :2004-8-11
最后修改日期 :2004-8-12
测试:
LCD_write_chi(0,0,12,7,0,0);
LCD_write_chi(0,2,12,7,0,0);
LCD_write_chi(0,4,12,7,0,0);
-----------------------------------------------------------------------*/
void LCD_write_chinese_string(unsigned char X, unsigned char Y,
unsigned char ch_with,unsigned char num,
unsigned char line,unsigned char row)
{
unsigned char i,n;
LCD_set_XY(X,Y); //设置初始位置
for (i=0;i<num;)
{
for (n=0; n<ch_with*2; n++) //写一个汉字
{
if (n==ch_with) //写汉字的下半部分
{
if (i==0) LCD_set_XY(X,Y+1);
else
LCD_set_XY((X+(ch_with+row)*i),Y+1);
}
LCD_write_byte(write_chinese_string[line+i][n],1);
}
i++;
LCD_set_XY((X+(ch_with+row)*i),Y);
}
}
/*-----------------------------------------------------------------------
LCD_move_chinese_string: 汉字移动
输入参数:X、Y :显示汉字的起始X、Y坐标;
T :移动速度;
编写日期 :2004-8-13
最后修改日期 :2004-8-13
-----------------------------------------------------------------------*/
void LCD_move_chinese_string (unsigned char X, unsigned char Y, unsigned char T)
{
unsigned char i,n,j=0;
unsigned char buffer_h[84]={0};
unsigned char buffer_l[84]={0};
for (i=0; i<252; i++) //周期
{
buffer_h[83] = move_chinese_string[i/12][j];
buffer_l[83] = move_chinese_string[i/12][j+12];
j++;
if (j==12) j=0;
for (n=0; n<83; n++)
{
buffer_h[n]=buffer_h[n+1];
buffer_l[n]=buffer_l[n+1];
}
LCD_set_XY(X,Y);
for (n=0; n<83; n++)
{
LCD_write_byte(buffer_h[n],1);
}
LCD_set_XY(X,Y+1);
for (n=0; n<83; n++)
{
LCD_write_byte(buffer_l[n],1);
}
for(i=T;i>0;i--)
delay_ms(1);
}
}
/*-----------------------------------------------------------------------
LCD_draw_map : 位图绘制函数
输入参数:X、Y :位图绘制的起始X、Y坐标;
*map :位图点阵数据;
Pix_x :位图像素(长)
Pix_y :位图像素(宽)
编写日期 :2004-8-13
最后修改日期 :2004-8-13
-----------------------------------------------------------------------*/
void LCD_draw_bmp_pixel(unsigned char X,unsigned char Y,unsigned char *map,
unsigned char Pix_x,unsigned char Pix_y)
{
unsigned int i,n;
unsigned char row;
if (Pix_y%8==0) row=Pix_y/8; //计算位图所占行数
else
row=Pix_y/8+1;
for (n=0;n<row;n++)
{
LCD_set_XY(X,Y);
for(i=0; i<Pix_x; i++)
{
LCD_write_byte(map[i+n*Pix_x], 1);
}
Y++; //换行
}
}
/*-----------------------------------------------------------------------
LCD_write_byte : 使用模拟SPI接口写数据到LCD
输入参数:data :写入的数据;
command :写数据/命令选择;
编写日期 :2004-8-10
最后修改日期 :2004-8-13
-----------------------------------------------------------------------*/
void LCD_write_byte(unsigned char data, unsigned char command)
{
unsigned char i;
P2OUT &= ~LCD_CE ; // 使能LCD
P2OUT&=~SPI_CLK;
if (command == 0)
P2OUT &= ~LCD_DC; // 传送命令
else
P2OUT |= LCD_DC; // 传送数据
for(i=8;i>0;i--)
{
P2OUT&=~SPI_CLK;
delay_us(1);
if(data&BIT7)
P2OUT|= SPI_MOSI; //送1
else P2OUT&=~SPI_MOSI; //送0
delay_us(1);
P2OUT|=SPI_CLK; //上升沿上传数据
data<<=1;
}
delay_us(1);
P2OUT&=~SPI_CLK;
delay_us(1);
P2OUT|=SPI_CLK;
P2OUT|= LCD_CE ; // 关闭LCD
}
//------------------------------
//初始化系统时钟
//----------------------------------------*/
void int_clk()
{
unsigned char i;
BCSCTL1&=~XT2OFF; //打开XT振荡器
BCSCTL2|=SELM1+SELS;//MCLK 8M and SMCLK 1M
do
{
IFG1 &= ~OFIFG; //清除振荡错误标志
for(i = 0; i < 100; i++)
_NOP(); //延时等待
}
while ((IFG1 & OFIFG) != 0); //如果标志为1继续循环等待
IFG1&=~OFIFG;
}
int main()
{
WDTCTL=WDTPW+WDTHOLD; //关闭看门狗
int_clk(); //初始化系统时钟
P2DIR=0xff; //p1 output
LCD_init(); //初始化LCD
LCD_write_english_string(0,5,"China Mobile ");
while(1)
{
_NOP();
// delay_ms(1000);
// P1OUT|=0x01;
//delay_ms(1000);
// P1OUT&=~0x01;
//LCD_write_chinese_string(0,3,12,3,0,0); //显示“我们的”,在x=0,y=2位置,显示write_chinese_string的12点阵汉字,
//显示4个,从第0个开始显示,行距为0,
//LCD_draw_bmp_pixel(36,2,AVR_bmp,50,24); //显示AVR大图 //48 32
LCD_write_english_string(0,5,"China Mobile ");
// LCD_move_chinese_string(0, 0, 50); //在屏幕最上面一行显示:欢迎光临本网站!显示速度为100,数值越大,速度越慢。
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -