日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]/********************************************************************1602液晶顯示********************************************************************/ #include #define CPU_F ((double)8000000) #define

/********************************************************************

1602液晶顯示

********************************************************************/

#include

#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

#define P10 3

#define P11 6

#define P12 7

#define RS_CLR P3OUT &= ~(1 << P10) //RS置低

#define RS_SET P3OUT |= (1 << P10) //RS置高

#define RW_CLR P3OUT &= ~(1 << P11) //RW置低

#define RW_SET P3OUT |= (1 << P11) //RW置高

#define EN_CLR P3OUT &= ~(1 << P12) //E置低

#define EN_SET P3OUT |= (1 << P12) //E置高

#define DataPort P4OUT //P4口為數(shù)據(jù)口

#define KeyPort P1IN //獨(dú)立鍵盤(pán)接在P14~P17

#define LED P2OUT //LED燈接在P2上

uchar key;

uchar temp,keynum = 0;

int shi=23,fen=59,miao=58;

//*************************************************************************

// 系統(tǒng)時(shí)鐘初始化

//*************************************************************************

void Clock_Init()

{

uchar i;

BCSCTL1&=~XT2OFF; //打開(kāi)XT振蕩器

BCSCTL2|=SELM1+SELS; //MCLK為8MHZ,SMCLK為8MHZ

do{

IFG1&=~OFIFG; //清除震蕩標(biāo)志

for(i=0;i<100;i++)

_NOP(); //延時(shí)等待

}

while((IFG1&OFIFG)!=0); //如果標(biāo)志為1,則繼續(xù)循環(huán)等待

IFG1&=~OFIFG;

}

//*************************************************************************

// MSP430內(nèi)部看門(mén)狗初始化

//*************************************************************************

void WDT_Init()

{

WDTCTL = WDTPW + WDTHOLD; //關(guān)閉看門(mén)狗

}

//*************************************************************************

// 初始化IO口子程序

//*************************************************************************

void Port_init()

{

P1SEL = 0x00; //P2普通IO功能

P1DIR = 0x0F; //P24~P27輸入模式,外部電路已接上拉電阻

P2SEL = 0x00; //P5口普通IO功能

P2DIR = 0xFF;

// LED = 0X00; //P5口輸出模式

P4SEL = 0x00;

P4DIR = 0xFF;

P3SEL = 0x00;

P3DIR|= BIT3 + BIT6 + BIT7; //控制口設(shè)置為輸出模式

}

//***********************************************************************

// 顯示屏命令寫(xiě)入函數(shù)

//***********************************************************************

void LCD_write_com(unsigned char com)

{

RS_CLR;

RW_CLR;

EN_SET;

DataPort = com; //命令寫(xiě)入端口

delay_ms(5);

EN_CLR;

}

//***********************************************************************

// 顯示屏數(shù)據(jù)寫(xiě)入函數(shù)

//***********************************************************************

void LCD_write_data(unsigned char data)

{

RS_SET;

RW_CLR;

EN_SET;

DataPort = data; //數(shù)據(jù)寫(xiě)入端口

delay_ms(5);

EN_CLR;

}

//***********************************************************************

// 顯示屏清空顯示

//***********************************************************************

void LCD_clear(void)

{

LCD_write_com(0x01); //清屏幕顯示

delay_ms(5);

}

//***********************************************************************

// 寫(xiě)入時(shí)分秒

//***********************************************************************

void LCD_write_sfm(uchar add,uchar dat)

{

uchar a,b;

a = dat/10;

b = dat%10;

LCD_write_com(0xc0 + add);

LCD_write_data(a+0x30);

LCD_write_data(b+0x30);

}

//***********************************************************************

// 顯示屏字符串寫(xiě)入函數(shù)

//***********************************************************************

void LCD_write_str(unsigned char x,unsigned char y,unsigned char *s)

{

if (y == 0)

{

LCD_write_com(0x80 + x); //第一行顯示

}

else

{

LCD_write_com(0xC0 + x); //第二行顯示

}

while (*s)

{

LCD_write_data( *s);

s ++;

}

}

//***********************************************************************

// 顯示屏單字符寫(xiě)入函數(shù)

//***********************************************************************

void LCD_write_char(unsigned char x,unsigned char y,unsigned char data)

{

if (y == 0)

{

LCD_write_com(0x80 + x); //第一行顯示

}

else

{

LCD_write_com(0xC0 + x); //第二行顯示

}

LCD_write_data( data);

}

//***********************************************************************

// 顯示屏初始化函數(shù)

//***********************************************************************

void LCD_init(void)

{

LCD_write_com(0x38); //顯示模式設(shè)置

delay_ms(5);

LCD_write_com(0x08); //顯示關(guān)閉

delay_ms(5);

LCD_write_com(0x01); //顯示清屏

delay_ms(5);

LCD_write_com(0x06); //顯示光標(biāo)移動(dòng)設(shè)置

delay_ms(5);

LCD_write_com(0x0C); //顯示開(kāi)及光標(biāo)設(shè)置

delay_ms(5);

}

//***********************************************************************

// 時(shí)鐘顯示

//***********************************************************************

void clock(void)

{

miao++;

if(miao==60)

{

miao=0;

fen++;

if(fen==60)

{

fen=0;

shi++;

if(shi==24)

{

shi=0;

}

LCD_write_sfm(2,shi);

}

LCD_write_sfm(5,fen);

}

LCD_write_sfm(8,miao);

}

//***********************************************************************

// 按鍵檢測(cè)

//***********************************************************************

uchar Key_Scan(void)

{

uchar key_check;

uchar key_checkin;

key_check

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專(zhuān)欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉