G题-报告1-程序清单 | ||||
| ||||
G题-报告1-程序清单 关键模块程序清单 #include <msp430.h> #define uchar unsigned char //宏定义 #define uint unsigned int #define dispLAY 0x00|0x0c //显示控制字 #define VidEO_RAM_ALL_RESET 0x34 //清空RAM控制字 #define display_character1 0XC0|CHARLOW4 //显示字符控制字 #define CHARLOW4 0X0f #define DATA6453 BIT5 #define CLK6453 BIT6 #define CS6453 BIT4 #define BUSY6453 BIT7 void nop (void) //延时函数定义 { uint j; for(j = 0;j<200;j++) { ; } } void delay (uint ms) //延时函数定义 { uchar l; {while(ms--) { for(l=0;l<200;l++) {;} } } }
void init_serial(void) //初始化函数 { P3DIR = CLK6453 + DATA6453 + CS6453 + BUSY6453; P3OUT = CLK6453 + DATA6453 + CS6453 + BUSY6453; delay(100); P3DIR &= ~BUSY6453; //BUSY端口改为输入端 }
/****************************************************************************************
*****************************************************************************************/
static void RLDATA(uchar ch) //写入函数声明结构体 { uchar i=8; while (P3IN & BUSY6453 == BUSY6453); do { P3OUT &= ~CLK6453; if((ch&0x80)== 0x80){ P3OUT |= DATA6453; } else{ P3OUT &= ~DATA6453; } ch=ch<<1; P3OUT |= CLK6453; } while(--i); }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer uchar w,i; delay(300); init_serial(); w=VidEO_RAM_ALL_RESET; P3OUT &= ~CS6453; RLDATA(w); P3OUT |= CS6453; nop(); w=dispLAY; P3OUT &= ~CS6453; RLDATA(w); P3OUT |= CS6453; nop();
w=0x40;//背景控制字定义 P3OUT &= ~CS6453; RLDATA(w);//写入背景控制字 P3OUT |= CS6453; nop();
w=0x10;//背景控制字定义 P3OUT &= ~CS6453; RLDATA(w);//写入背景控制字 P3OUT |= CS6453; nop();
w=0x30;//背景控制字定义 P3OUT &= ~CS6453; RLDATA(w);//写入背景控制字 P3OUT |= CS6453; nop();
for (i = 0; i < 12; i++) { P3OUT &= ~CS6453; w=0x89; RLDATA(w); RLDATA(0x30+i); P3OUT |= CS6453; } nop();
w=0x80; //写入B或C P3OUT &= ~CS6453; RLDATA(w); w=0x00; RLDATA(w); P3OUT |= CS6453;
w=0x84; //确定坐标值X P3OUT &= ~CS6453; RLDATA(w); w=0x45;// 确定坐标值y RLDATA(w); P3OUT |= CS6453; nop(); w=display_character1; P3OUT &= ~CS6453; RLDATA(w); w=0x0C; //确定写入的字符地址,0x0c代表C 0x0b代表B RLDATA(w);
delay(1000); _bis_SR_register(LPM3_bits); while(1){}; return 0; } |