#include <msp430f5529.h>
#define unchar unsigned char
#define uint unsigned char
static double data;//用来存储ADC12MEM中的数据
int a,b,c=0; //用来存储将要显示在LCD上的各位数据
//#define CS P2DIR |= BIT2
#define CS_H P2OUT |= BIT2
#define CS_L P2OUT &= ~BIT2
//#define SID P2DIR |= BIT3
#define SID_H P2OUT |= BIT3
#define SID_L P2OUT &= ~BIT3
//#define SCLK P2DIR |= BIT4
#define SCLK_H P2OUT |= BIT4
#define SCLK_L P2OUT &= ~BIT4
//#define RST P2DIR |= BIT5
#define RST_H P2OUT |= BIT5
#define RST_L P2OUT &= ~BIT5
#define PSB_L P2OUT &= ~BIT6
/*void delay( unchar t);
void sendbyte( unchar z);
void write_com( unchar cmd);
void write_data(unchar disp);
void init_lcd();
void lcd_clear();
void diszfc( char *s);
void test ();
void gotoxy(uint x,uint y);
void initADC12();
void SendDouble(double data);
*/
void delay( unchar t)
{
uint i , j ;
for(i = 0; i < t ;i ++)
for (j = 0; j < 10; j++);
}
void sendbyte( unchar z)
{
uint i;
for(i = 0; i <8; i ++)
{
if ((z<<i) & 0x80)
{
SID_H; //P2OUT |= BIT3;
}
else
{
SID_L;//P2OUT &= ~BIT3;
}
SCLK_L;//P2OUT &= ~BIT4;
SCLK_H;//P2OUT |= BIT4;
}
}
void write_com( unchar cmd) //写串口指令
{
CS_H;//P2OUT |= BIT2;
sendbyte (0xf8); //输指令
sendbyte (cmd & 0xf0);
sendbyte ((cmd << 4) & 0xf0);
delay(2);
}
void write_data(unchar disp) //写数据
{
CS_H;//P2OUT |= BIT2;
sendbyte(0xfa);//传数据
sendbyte(disp & 0xf0);
sendbyte((disp << 4) & 0xf0);
delay(2);
}
void lcd_clear()
{
write_com(0x01); //清屏指令
write_com(0x02); //光标归位 即光标置于左上位置
}
void init_lcd()
{
RST_L;//P2OUT &= ~BIT5;//RST = 0;
delay(100);
RST_H;//P2OUT |= BIT5;//RST = 1;
delay(100);
write_com(0x30); //基本指令操作
delay(50);
write_com(0x0c); //显示开关闭光标
delay(50);
}
/*void diszfc( char *s) //显示字符串
{
while ( *s > 0)
{
write_data(*s);
s++;
delay(50);
}
}*/
/*void gotoxy(uint x,uint y) //定位 ,x为行,y为列
{
unchar wz;
switch(x)
{
case 1: wz=0x80; break;//当x为1指向第一行
case 2: wz=0x90; break;//当x为2指向第二行
case 3: wz=0x88; break;//当x为3指向第三行
case 4: wz=0x98; break;//当x为4指向第四行
default: wz=0x80; //x为其它值时指向第一行
}
wz=wz+y;
write_com(wz);
}
void test ()
{
write_com(0x03);
delay(50);
//write_com(0x81);
gotoxy(1,00);diszfc("R:");
gotoxy(1,01);diszfc("123");
//write_com(0x91);
gotoxy(2,00);diszfc("G:");
gotoxy(2,01);diszfc("222");
gotoxy(3,00);diszfc("B:");
gotoxy(3,01);diszfc("111");
}
*/
void initADC12()
{
P6SEL=0X01;//P6.0作为模拟输入
ADC12IE=0X01; //开放中断ADC12IFG.0
ADC12CTL0=ADC12ON+ADC12SHT0_4+ADC12REFON+ADC12REF2_5V;//打开ADC转换的核,采用内部参考电压2.5v;
ADC12CTL1=ADC12SHP; //信号源内部触发
ADC12MCTL0=ADC12SREF_1;//使用内部2.5V作为参考电压
ADC12CTL0 |=ADC12ENC; //开放使能
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR()
{
data=ADC12MEM0*2.5/4095; //data为全局变量
write_com(0x02);
_BIC_SR_IRQ(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
void SendDouble(double data)
{
data *=100;
int temp =(int)data;
a = temp/100;//考虑到由于内部参考电压的限制,且仅考虑两位小数的情况
b = (temp%100)/10;
c = temp%10;
write_data(a+0x30);
write_data(*.*);
write_data(b+0x30);
write_data(c+0x30);
write_data(* *);
write_data(*V*);
}
void main(void)
{
WDTCTL = WDTPW | WDTHOLD;// Stop watchdog timer
double temp=0.0;
P2DIR |= BIT2 + BIT3 + BIT4 + BIT5 + BIT6;
PSB_L;
delay(1);
init_lcd();
initADC12();
lcd_clear();
delay(10);
while(1)
{
ADC12CTL0 |= ADC12SC; // Sampling open
_BIS_SR(CPUOFF + GIE); // LPM0, ADC12_ISR will force exit
if(temp!=data)
{
temp=data;
SendDouble(data);
}
}
}
求助啊
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>