《用MSP430G2553单片机控制Ht1621的程序及笔记.doc》由会员分享,可在线阅读,更多相关《用MSP430G2553单片机控制Ht1621的程序及笔记.doc(32页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-date用MSP430G2553单片机控制Ht1621的程序及笔记用MSP430G2553单片机控制Ht1621的程序及笔记型号:HT1621BS725G01012液晶全部显示时如下图:6位数字、3个小数点和右方电源标志全部点亮函数:/*全部点亮*/ void HT1621_all_on(uchar num) uchar i; uchar addr=0; for(i=0;in
2、um;i+) Write_1621(addr,0xff); addr+=2; 屏幕数字笔画对应编码:程序例子:#include msp430g2553.h#define uint unsigned int#define uchar unsigned char/*定义1621的端口*/#define DATA1 P2OUT|=BIT0/1621DATA端口#define DATA0 P2OUT&=BIT0#define WR1 P2OUT|=BIT1/1621WR0端口#define WR0 P2OUT&=BIT1#define CS1 P2OUT|=BIT2/1621CS端口#define C
3、S0 P2OUT&=BIT2/*定义HT1621的命令*/ #define ComMode 0x52 /4COM,1/3bias 1000 010 1001 0 #define RCosc 0x30 /内部RC振荡器(上电默认)1000 0011 0000 #define LCD_on 0x06 /打开LCD 偏压发生器1000 0000 0 11 0 #define LCD_off 0x04 /关闭LCD显示 #define Sys_en 0x02 /系统振荡器开 1000 0000 0010 #define CTRl_cmd 0x80 /写控制命令 #define Data_cmd 0xa
4、0 /写数据命令 char dispnum6=0x00,0x00,0x00,0x00,0x00,0x00;/用来存放要显示的数字const char num=0x7d,0x60,0x3e,0x7a,0x63,0x5b,0x5f,0x70,0x7f,0x7b; /*0,1,2,3,4,5,6,7,8,9*/*延时子程序*/void delay_1us(void) /1us延时函数 asm(nop);/N us延时函数void delaynus(uint n) uint i; for(i=0;in;i+) asm(nop);void delay_1ms(void) /1ms延时函数 unsigne
5、d int i; for (i=0;i1140;i+); void delay_nms(unsigned int n) /N ms延时函数 unsigned int i=0; for (i=0;in;i+) delay_1ms();/*发送数据*/void SendBit_1621(uchar sdata,uchar cnt) /data 的高cnt 位写入HT1621,高位在前 uchar i; for(i=0;icnt;i+) WR0; delaynus(20); /8M必须加,4M可省略 if(sdata&0x80) DATA1; else DATA0; delaynus(20);/8M
6、必须加,4M可省略 WR1; delaynus(20); /8M必须加,4M可省略 sdata=1; delaynus(20); /*送命令*/void SendCmd_1621(uchar command) CS0; SendBit_1621(0x80,4); /写入标志码“100”和9 位command 命令,由于 SendBit_1621(command,8); /没有使有到更改时钟输出等命令,为了编程方便 CS1; /直接将command 的最高位写“0” /*发送数据和命令*参数说明:addr:要在第几位显示*/void Write_1621(uchar addr,uchar sda
7、ta) addr=2; CS0; SendBit_1621(0xa0,3); /写入标志码“101” SendBit_1621(addr,6); /写入addr 的高6位,*6位显示 SendBit_1621(sdata,8); /写入data的8位 CS1; /*清除显示*参数说明:num:要清除几位*/void HT1621_all_off(uchar num) uchar i; uchar addr=0; for(i=0;inum;i+) Write_1621(addr,0x00); addr+=2; /*全部点亮*参数说明:num:要点亮几位*/ void HT1621_all_on(
8、uchar num) uchar i; uchar addr=0; for(i=0;inum;i+) Write_1621(addr,0xff); addr+=2; /*全部点亮1621,显示同样的数字*参数说明:num:要显示几位*/ void HT1621_all_on_num(uchar num,uchar xx) uchar i; uchar addr=0; for(i=0;inum;i+) Write_1621(addr,xx); addr+=2; /*(初始化1621)*/ void Init_1621(void) SendCmd_1621(Sys_en);/系统振荡器开 Send
9、Cmd_1621(RCosc); /内部RC振荡器 SendCmd_1621(ComMode); /4COM,1/3bias 1000 010 1001 0 SendCmd_1621(LCD_on);/打开LCD 偏压发生器1000 0000 0 11 0/*初始化1621) */ void LCDoff(void) SendCmd_1621(LCD_off); /*Name: LCDon(初始化1621)*/ void LCDon(void) SendCmd_1621(LCD_on); void displayallnum(unsigned int n) /各位显示所有数码字符函数 ucha
10、r i,j; uchar addr=0; for(i=0;in;i+) for(j=0;j29;j+) Write_1621(addr,numj); delay_nms(100) ; addr+=2; /测试第2位数码各位笔画,用于编写num数组void displaybihua(void) Write_1621(2,0x01); delay_nms(350) ; Write_1621(2,0x02); delay_nms(350) ; Write_1621(2,0x04); delay_nms(350) ; Write_1621(2,0x08); delay_nms(350) ; Write
11、_1621(2,0x10); delay_nms(350) ; Write_1621(2,0x20); delay_nms(350) ; Write_1621(2,0x40); delay_nms(350) ; Write_1621(2,0x80); delay_nms(350) ; /逐位显示各位8字+小数点void displayall8(void) uchar i; HT1621_all_off(6); for(i=0;i6;i+) Write_1621(2*i,0xff); delay_nms(50) ; /显示数组数据void displaydata(long int t,int p
12、) uchar i; dispnum4=numt/10000; dispnum3=num(t/1000)%10; dispnum2=num(t/100)%10; dispnum1=num(t/10)%10; dispnum0=numt%10; /*switch(p) case 1: sbi(dispnum0, 4); break; case 2: sbi(dispnum1, 4); break; case 3: sbi(dispnum2, 4); break; default:break; */ for(i=0;i5;i+) Write_1621(i*2,dispnumi); void main() WDTCTL = WDTPW + WDTHOLD; long int t=0; uchar i; P2DIR=0xff; Init_1621() ;/初始化 HT1621_all_on(6);/全部点亮 delay_nms(200); HT1621_all_off(16);/全部关闭 delay_nms(50); for(i=0;i99999) t=0; delay_nms(20); -