ntc热敏电阻测温、12864显示
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include "msp430g2553.h"
#define SID BIT3
#define SCLK BIT4
#define CS BIT5
#define LCDPORT P1OUT
#define SID_H LCDPORT |= SID
#define SID_L LCDPORT &= ~SID
#define SCLK_H LCDPORT |= SCLK
#define SCLK_L LCDPORT &= ~SCLK
#define CS_H LCDPORT |= CS
#define CS_L LCDPORT &= ~CS
unsigned char i,j;
unsigned int kj;
char temp[4];
float kk;
void delay(unsigned char ms)
{
for(i=ms;i>0;i--)
for(j=120;j>0;j--);
}
void wr_lcd (unsigned char dat,unsigned char content)//读lcd
{
unsigned char a123,i123,j123,b123,C123,d123;
d123=0x80;
b123=dat;
a123=content;
SCLK_L; delay(5);
CS_H; delay(5);
SID_H; delay(5);
for(i123=0;i123<5;i123++)
{
SCLK_H; delay(5);
SCLK_L; delay(5);//同步脉冲高五 位置1
}
if(b123==1)
{//------写数据
SID_L; delay(5);
SCLK_H; delay(5);
SCLK_L; delay(5);
SID_H; delay(5);
SCLK_H; delay(5);
SCLK_L; delay(5);
SID_L; delay(5);
SCLK_H; delay(5);
SCLK_L; delay(5);
}
else if(b123==0)
{//------写指令
SID_L; delay(5);
SCLK_H; delay(5);
SCLK_L; delay(5);
SCLK_H; delay(5);
SCLK_L; delay(5);
SCLK_H; delay(5);
SCLK_L; delay(5);
}
for(j123=0;j123<2;j123++)
{
for(i123=0;i123<4;i123++) //8位数据的高4位
{
C123=d123&a123;
if(C123==0)
{
SID_L; delay(5);
}
else
{
SID_H; delay(5);
}
SCLK_H; delay(5);
SCLK_L; delay(5);
d123=d123>>1;
}
SID_L;delay(5);
for(i123=0;i123<4;i123++) //8位数据的低4位
{
SCLK_H; delay(5);
SCLK_L; delay(5);
}
}
CS_L;
SCLK_L;
SID_H;
delay(5);
}
void lcd_show(unsigned char x, unsigned char y,char *ptr)//LCD显示
{
unsigned char address,L=0,j=0; //L=0;如果不初始化,显示对不上位
if(x<=1)
{
j=x*16+y;
address=j+0x80;
wr_lcd(0x00,address);
}
else if(x==0x02)
{
j=0x88+y;
address=j;
wr_lcd(0x00,address);
}
else if(x==0x03)
{
j=0x98+y;
address=j;
wr_lcd(0x00,address);
}
while(ptr[L]!=0x00)
{
if(j==0)
{
wr_lcd(0x00,0x80);
}
if(j==16)
{
wr_lcd (0x00,0x90);
}
if(j==32)
{
wr_lcd (0x00,0x88);
}
if(j==48)
{
wr_lcd (0x00,0x98);
}
if(j==64)
{
;
}
wr_lcd (0x01,ptr[L]);
L++;
}
}
void lcd_int()//LCD初始化
{
CS_L; //cs_off;
SID_L; //sid_off ;
SCLK_L; //sclk_off;
delay(5);delay(5);
wr_lcd(0x00,0x30); //30---基本指令动作
wr_lcd(0x00,0x01); //清屏,地址指针指向00H
delay(5);delay(5);delay(5);
wr_lcd(0x00,0x06); //光标的移动方向
wr_lcd(0x00,0x0c); //开显示,关游标
//0x00代表写指令,0x01代表写数据
}
void w_d()
{
if(kk>5004.08)
{
temp[0]=0x32;
temp[1]=0x34;
}
if((kk<=5004.08)&&(kk>4633.91))
{
temp[0]=0x32;
tem
p[1]=0x36;
}
if((kk<=4633.91)&&(kk>4294.94))
{
temp[0]=0x32;
temp[1]=0x38;
}
if((kk<=4294.94)&&(kk>3984.17))
{
temp[0]=0x33;
temp[1]=0x30;
}
if((kk<=3984.17)&&(kk>3698.91))
{
temp[0]=0x33;
temp[1]=0x32;
}
if((kk<=3698.91)&&(kk>3437.11))
{
temp[0]=0x33;
temp[1]=0x34;
}
if((kk<=3437.11)&&(kk>3196.5))
{
temp[0]=0x33;
temp[1]=0x36;
}
if((kk<=3196.5)&&(kk>2972.61))
{
temp[0]=0x33;
temp[1]=0x38;
}
if((kk<=2972.61)&&(kk>2768.73))
{
temp[0]=0x34;
temp[1]=0x30;
}
if((kk<=2768.73)&&(kk>2583.32))
{
temp[0]=0x34;
temp[1]=0x32;
}
if((kk<=2583.32)&&(kk>2409.96))
{
temp[0]=0x34;
temp[1]=0x34;
}
if((kk<=2409.96)&&(kk>2249.9))
{
temp[0]=0x34;
temp[1]=0x36;
}
if((kk<=2249.9)&&(kk>2102.52))
{
temp[0]=0x34;
temp[1]=0x38;
}
if((kk<=2102.52)&&(kk>1965.72))
{
temp[0]=0x35;
temp[1]=0x30;
}
if(kk<1965.72)
{
temp[0]=0x35;
temp[1]=0x35;
}
temp[2]=0x43;
temp[3]=0x00;
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR = 0xFD;
lcd_int();
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON+ ADC10IE;
__enable_interrupt();
TACCR0 = 30;
TACCTL0 |= CCIE;
TACTL = TASSEL_2 | MC_1;
LPM0;
TACCTL0 &= ~CCIE;
__disable_interrupt();
ADC10CTL1 = INCH_1;
ADC10AE0 |= 0x02;
P1DIR |= 0x01;
while(1)
{
ADC10CTL0 |= ENC + ADC10SC;
__bis_SR_register(GIE);
kj=ADC10MEM;
kk=3500/(kj*1.5/1023)-1000;
w_d();
lcd_show(0,1,"当前温度:");
lcd_show(1,1,temp);
}
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF);
//kj=ADC10MEM;
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void ta0_isr(void)
{
TACTL = 0;
LPM0_EXIT;
}