unsigned int time_counter=0;
unsigned int ADC_voltage=0;
unsigned int tempData,ADC_voltageDataOld;
unsigned int tempDataOld,ADC_voltageData;
volatile long IntDegF;
volatile long IntDegC;
volatile long temp;
button_init();
Dogs102x6_imageDraw(clock_disp,0,35);
Dogs102x6_stringDraw(2,0,time,DOGS102x6_DRAW_NORMAL); // write data to LCD
Dogs102x6_stringDraw(3,0,clock,DOGS102x6_DRAW_NORMAL); // write data to LCD
ADC_init();
P1DIR |= (0x01<<0);
P8DIR |= (0x01<<2);
while(1)
{
ADC12CTL0 |= ADC12SC;
display_ADC();
display_time();
key_scan();
clock_check();
}
}
uint16_t get_temp_Value(void)
{
if (tempData > tempDataOld)
if ((tempData - tempDataOld) > 10)
tempDataOld = tempData; //use new data if change is beyond
// fluctuation threshold
else
tempData = tempDataOld; //use old data if change is not beyond
// fluctuation threshold
else
if ((tempDataOld - tempData) > 10)
tempDataOld = tempData; //use new data if change is beyond
// fluctuation threshold
else
tempData = tempDataOld; //use old data if change is not beyond
// fluctuation threshold
return tempData;
}
uint16_t get_ADC_voltage_Value(void)
{
if (ADC_voltageData > ADC_voltageDataOld)
if ((ADC_voltageData - ADC_voltageDataOld) > 10)
ADC_voltageDataOld = ADC_voltageData; //use new data if change is beyond
// fluctuation threshold
else
ADC_voltageData = ADC_voltageDataOld; //use old data if change is not beyond
// fluctuation threshold
else
if ((ADC_voltageDataOld - ADC_voltageData) > 10)
ADC_voltageDataOld = ADC_voltageData; //use new data if change is beyond
// fluctuation threshold
else
ADC_voltageData = ADC_voltageDataOld; //use old data if change is not beyond
// fluctuation threshold
Dogs102x6_stringDraw(4,0,temp1,DOGS102x6_DRAW_NORMAL); // write data to LCD
Dogs102x6_stringDraw(5,0,temp2,DOGS102x6_DRAW_NORMAL); // write data to LCD
Dogs102x6_stringDraw(6,0,adc_volage,DOGS102x6_DRAW_NORMAL); // write data to LCD
}
void ADC_init(void)
{
P8DIR |= BIT0;
P8OUT |= BIT0; // Enable WHEEL
REFCTL0 &= ~REFMSTR;
ADC12CTL0 = ADC12SHT0_8 + ADC12REFON + ADC12ON;
ADC12CTL0 |= ADC12ON+ADC12MSC+ADC12SHT0_2+ADC12SHT1_2+ADC12SHT0_8; // Turn on ADC12, set sampling time
ADC12CTL1 = ADC12SHP+ADC12CONSEQ_1; // Use sampling timer, single sequence
#include <stdint.h>
#include <msp430f5529.h>
#include "msp430.h"
#include "HAL_Dogs102x6.h"
void lcd_int(void);
void time_1_int(void);
void display_time(void);
void display_style(void);
void button_init(void);
void key_scan(void);
void clock_check(void);
void display_ADC(void);
void ADC_init(void);
uint16_t get_temp_Value(void);
uint16_t get_ADC_voltage_Value(void);
char hour=0,min=0,sec=0;
char clk_hour=0,clk_min=0,clk_sec=20;
char key_chose=5;
unsigned int time_counter=0;
unsigned int ADC_voltage=0;
unsigned int tempData,ADC_voltageDataOld;
unsigned int tempDataOld,ADC_voltageData;
volatile long IntDegF;
volatile long IntDegC;
volatile long temp;
uint8_t time_hour_style=0;
uint8_t time_min_style=0;
uint8_t clk_hour_style=0;
uint8_t clk_min_style=0;
uint8_t clk_sec_style=0;
char time[] ="time :00-00-00";
char clock[]="clock:00-00-00";
char time_hour[]="00";
char time_min[]="00";
char time_sec[]="00";
char clock_disp_hour[]="00";
char clock_disp_min[]="00";
char clock_disp_sec[]="00";
char temp1[]="AD_IntDegF=0000";
char temp2[]="AD_IntDegC=0000";
char adc_volage[]="ADC_votage=0000";
const uint8_t clock_disp[]={0x20,0x02,
0x00,0x1F,0x80,0x44,0x04,0x44,0x54,0x4F,0x44,0x44,0x44,0x44,0x40,0x7F,0x00,0x00,
0x04,0x08,0x34,0xE7,0x24,0x24,0x00,0x0F,0x08,0x08,0xFF,0x08,0x08,0x0F,0x00,0x00,
0x00,0xFF,0x00,0x00,0xF8,0x80,0x80,0xFE,0x90,0x88,0xF0,0x02,0x01,0xFE,0x00,0x00,
0x80,0x80,0x80,0xFE,0x84,0x88,0x00,0xE0,0x40,0x40,0xFF,0x40,0x40,0xE0,0x00,0x00
}; //display"naozhong"
void main( void )
{
WDTCTL = WDTPW + WDTHOLD;
time_1_int();
lcd_int();
button_init();
Dogs102x6_imageDraw(clock_disp,0,35);
Dogs102x6_stringDraw(2,0,time,DOGS102x6_DRAW_NORMAL); // write data to LCD
Dogs102x6_stringDraw(3,0,clock,DOGS102x6_DRAW_NORMAL); // write data to LCD
ADC_init();
P1DIR |= (0x01<<0);
P8DIR |= (0x01<<2);
while(1)
{
ADC12CTL0 |= ADC12SC;
display_ADC();
display_time();
key_scan();
clock_check();
}
}
uint16_t get_temp_Value(void)
{
if (tempData > tempDataOld)
if ((tempData - tempDataOld) > 10)
tempDataOld = tempData; //use new data if change is beyond
// fluctuation threshold
else
tempData = tempDataOld; //use old data if change is not beyond
// fluctuation threshold
else
if ((tempDataOld - tempData) > 10)
tempDataOld = tempData; //use new data if change is beyond
// fluctuation threshold
else
tempData = tempDataOld; //use old data if change is not beyond
// fluctuation threshold
return tempData;
}
uint16_t get_ADC_voltage_Value(void)
{
if (ADC_voltageData > ADC_voltageDataOld)
if ((ADC_voltageData - ADC_voltageDataOld) > 10)
ADC_voltageDataOld = ADC_voltageData; //use new data if change is beyond
// fluctuation threshold
else
ADC_voltageData = ADC_voltageDataOld; //use old data if change is not beyond
// fluctuation threshold
else
if ((ADC_voltageDataOld - ADC_voltageData) > 10)
ADC_voltageDataOld = ADC_voltageData; //use new data if change is beyond
// fluctuation threshold
else
ADC_voltageData = ADC_voltageDataOld; //use old data if change is not beyond
// fluctuation threshold
return ADC_voltageData;
}
void display_ADC(void)
{
ADC_voltage=get_ADC_voltage_Value();
temp=get_temp_Value();
IntDegC = ((temp - 1855) * 667) / 4096;
IntDegF = ((temp - 1748) * 1200) / 4096;
//IntDegC = temp;
//IntDegF = temp;
adc_volage[14]=ADC_voltage%10+'0';
adc_volage[13]=ADC_voltage/10%10+'0';
adc_volage[12]=ADC_voltage/100%10+'0';
adc_volage[11]=ADC_voltage/1000%10+'0';
temp1[14]=IntDegC%10+'0';
temp1[13]=IntDegC/10%10+'0';
temp1[12]=IntDegC/100%10+'0';
temp1[11]=IntDegC/1000%10+'0';
temp2[14]=IntDegF%10+'0';
temp2[13]=IntDegF/10%10+'0';
temp2[12]=IntDegF/100%10+'0';
temp2[11]=IntDegF/1000%10+'0';
Dogs102x6_stringDraw(4,0,temp1,DOGS102x6_DRAW_NORMAL); // write data to LCD
Dogs102x6_stringDraw(5,0,temp2,DOGS102x6_DRAW_NORMAL); // write data to LCD
Dogs102x6_stringDraw(6,0,adc_volage,DOGS102x6_DRAW_NORMAL); // write data to LCD
}
void ADC_init(void)
{
P8DIR |= BIT0;
P8OUT |= BIT0; // Enable WHEEL
REFCTL0 &= ~REFMSTR;
ADC12CTL0 = ADC12SHT0_8 + ADC12REFON + ADC12ON;
ADC12CTL0 |= ADC12ON+ADC12MSC+ADC12SHT0_2+ADC12SHT1_2+ADC12SHT0_8; // Turn on ADC12, set sampling time
ADC12CTL1 = ADC12SHP+ADC12CONSEQ_1; // Use sampling timer, single sequence
ADC12MCTL0 = ADC12INCH_5; // ref+=AVcc, channel = A5
ADC12MCTL1 = ADC12INCH_10+ADC12EOS+ ADC12SREF_1; // ref+=AVcc, channel = A10,end seq
P6SEL |= BIT5; // Enable A/D channel inputs
ADC12IE = 0x02; // Enable ADC12IFG.1
__delay_cycles(75); // 75us delay to allow Ref to settle
ADC12CTL0 |= ADC12ENC; // Enable conversions
}
void display_time(void)
{
time_hour[0]=hour/10+'0';
time_hour[1]=hour%10+'0';
time_min[0]=min/10+'0';
time_min[1]=min%10+'0';
time_sec[0]=sec/10+'0';
time_sec[1]=sec%10+'0';
clock_disp_hour[0]=clk_hour/10+'0';
clock_disp_hour[1]=clk_hour%10+'0';
clock_disp_min[0]=clk_min/10+'0';
clock_disp_min[1]=clk_min%10+'0';
clock_disp_sec[0]=clk_sec/10+'0';
clock_disp_sec[1]=clk_sec%10+'0';
display_style();
Dogs102x6_stringDraw(2,36,time_hour,time_hour_style);
Dogs102x6_stringDraw(2,54,time_min,time_min_style);
Dogs102x6_stringDraw(2,72,time_sec,DOGS102x6_DRAW_NORMAL);
Dogs102x6_stringDraw(3,36,clock_disp_hour,clk_hour_style);
Dogs102x6_stringDraw(3,54,clock_disp_min,clk_min_style);
Dogs102x6_stringDraw(3,72,clock_disp_sec,clk_sec_style);
}
void lcd_int(void)
{
Board_init(); // GPIO initialization
Dogs102x6_init(); // initialize LCD
Dogs102x6_clearScreen(); // clear screen of LCD
Dogs102x6_backlightInit(); // initialize the backlight of LCD
Dogs102x6_setBacklight(20); // set up the backlight of LCD
__enable_interrupt();//enable globle interrupt
}
void time_1_int(void)
{
TA1CCTL0 = CCIE; // CCR0 interrupt enabled
TA1CCR0 = 1045; //周期为1ms
TA1CTL = TASSEL_2 + MC_2 + TACLR; // SMCLK ~= 1.045MHz, contmode, clear TAR
__enable_interrupt();//enable globle interrupt
}
void button_init(void)
{
P1DIR &= ~(0x01<<7); //set P1.7 as input
P1REN |= (0x01<<7); //enable resistor
P1OUT |= (0x01<<7); //pull up
P2DIR &= ~(0x01<<2); //set P2.2 as input
P2REN |= (0x01<<2); //enable resistor
P2OUT |= (0x01<<2); //pull up
}
void key_scan(void)
{
unsigned int ii;
if(!(P1IN & (0x01<<7)))
{
for(ii=0;ii<10000;ii++);
if(!(P1IN & (0x01<<7)))
{
//P8OUT ^= (0x01<<2);
key_chose++;
if(key_chose==6)
{
key_chose=0;
}
}
while(!(P1IN & (0x01<<7))); //
for(ii=0;ii<10000;ii++); //
while(!(P1IN & (0x01<<7)));
}
if(!(P2IN & (0x01<<2)))
{
for(ii=0;ii<10000;ii++);
if(!(P2IN & (0x01<<2)))
{
//P1OUT ^= (0x01<<0);
if(key_chose==0)
{
hour++;
if(hour>=24)
{
hour=0;
}
}
if(key_chose==1)
{
min++;
if(min>=60)
{
min=0;
}
}
if(key_chose==2)
{
clk_hour++;
if(clk_hour>=24)
{
clk_hour=0;
}
}
if(key_chose==3)
{
clk_min++;
if(clk_min>=60)
{
clk_min=0;
}
}
if(key_chose==4)
{
clk_sec++;
if(clk_sec>=60)
{
clk_sec=0;
}
}
}
while(!(P2IN & (0x01<<2))); //
for(ii=0;ii<10000;ii++); //
while(!(P2IN & (0x01<<2)));
}
}
void clock_check(void)
{
unsigned ii,jj;
if (clk_sec==sec)
{
if(clk_min==min)
{
if(clk_hour==hour)
{
for (ii==0;ii<30;ii++)
{
P8OUT ^= (0x01<<2);
for(jj=0;jj<10000;jj++);
for(jj=0;jj<10000;jj++);
}
}
}
}
}
void display_style(void)
{
switch (key_chose)
{
case 0:
{
time_hour_style=1;
time_min_style=0;
clk_hour_style=0;
clk_min_style=0;
clk_sec_style=0;
}
break;
case 1:
{
time_hour_style=0;
time_min_style=1;
clk_hour_style=0;
clk_min_style=0;
clk_sec_style=0;
}
break;
case 2:
{
time_hour_style=0;
time_min_style=0;
clk_hour_style=1;
clk_min_style=0;
clk_sec_style=0;
}
break;
case 3:
{
time_hour_style=0;
time_min_style=0;
clk_hour_style=0;
clk_min_style=1;
clk_sec_style=0;
}
break;
case 4:
{
time_hour_style=0;
time_min_style=0;
clk_hour_style=0;
clk_min_style=0;
clk_sec_style=1;
}
break;
case 5:
{
time_hour_style=0;
time_min_style=0;
clk_hour_style=0;
clk_min_style=0;
clk_sec_style=0;
}
break;
default: break;
}
}
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{
++time_counter;
TA1CCR0 += 1045;
if (time_counter>=1000)
{
time_counter = 0;
sec++;
//P1OUT ^= BIT0;
if(sec==60)
{
sec=0;
min++;
if(min==60)
{
min=0;
hour++;
if(hour==24)
{
hour=0;
}
}
}
}
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
switch(__even_in_range(ADC12IV,34))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: break; // Vector 6: ADC12IFG0
case 8: // Vector 8: ADC12IFG1
ADC_voltageData = ADC12MEM0; // Move results, IFG is cleared
tempData = ADC12MEM1; // Move results, IFG is cleared
// __bic_SR_register_on_exit(LPM4_bits); // Exit active CPU
break;
case 10: break; // Vector 10: ADC12IFG2
case 12:break; // Vector 12: ADC12IFG3
case 14: break; // Vector 14: ADC12IFG4
case 16: break; // Vector 16: ADC12IFG5
case 18: break; // Vector 18: ADC12IFG6
case 20: break; // Vector 20: ADC12IFG7
case 22: break; // Vector 22: ADC12IFG8
case 24: break; // Vector 24: ADC12IFG9
case 26: break; // Vector 26: ADC12IFG10
case 28: break; // Vector 28: ADC12IFG11
case 30: break; // Vector 30: ADC12IFG12
case 32: break; // Vector 32: ADC12IFG13
case 34: break; // Vector 34: ADC12IFG14
default: break;
}
}
一周热门 更多>