#include
#include"HAL_Board.h"
#include"HAL_Dogs102x6.h"
unsigned int Result[8]={0};
unsigned int Average=0;
void zhuanhua(uint16_t num)
{
uint8_t ptr[4];
ptr[3] =num%10;
ptr[2] =num/10%10;
ptr[1] =num/100%10;
ptr[0] =num/1000;
switch(ptr[0])
{
case 0 :Dogs102x6_charDrawXY(10,30,'0',0);
break;
case 1 :Dogs102x6_charDrawXY(10,30,'1',0);
break;
case 2 :Dogs102x6_charDrawXY(10,30,'2',0);
break;
case 3 :Dogs102x6_charDrawXY(10,30,'3',0);
break;
case 4 :Dogs102x6_charDrawXY(10,30,'4',0);
break;
case 5 :Dogs102x6_charDrawXY(10,30,'5',0);
break;
case 6 :Dogs102x6_charDrawXY(10,30,'6',0);
break;
case 7 :Dogs102x6_charDrawXY(10,30,'7',0);
break;
case 8 :Dogs102x6_charDrawXY(10,30,'8',0);
break;
case 9 :Dogs102x6_charDrawXY(10,30,'9',0);
break;
}
switch(ptr[1])
{
case 0 :Dogs102x6_charDrawXY(16,30,'0',0);
break;
case 1 :Dogs102x6_charDrawXY(16,30,'1',0);
break;
case 2 :Dogs102x6_charDrawXY(16,30,'2',0);
break;
case 3 :Dogs102x6_charDrawXY(16,30,'3',0);
break;
case 4 :Dogs102x6_charDrawXY(16,30,'4',0);
break;
case 5 :Dogs102x6_charDrawXY(16,30,'5',0);
break;
case 6 :Dogs102x6_charDrawXY(16,30,'6',0);
break;
case 7 :Dogs102x6_charDrawXY(16,30,'7',0);
break;
case 8 :Dogs102x6_charDrawXY(16,30,'8',0);
break;
case 9 :Dogs102x6_charDrawXY(16,30,'9',0);
break;
}
switch(ptr[2])
{
case 0 :Dogs102x6_charDrawXY(22,30,'0',0);
break;
case 1 :Dogs102x6_charDrawXY(22,30,'1',0);
break;
case 2 :Dogs102x6_charDrawXY(22,30,'2',0);
break;
case 3 :Dogs102x6_charDrawXY(22,30,'3',0);
break;
case 4 :Dogs102x6_charDrawXY(22,30,'4',0);
break;
case 5 :Dogs102x6_charDrawXY(22,30,'5',0);
break;
case 6 :Dogs102x6_charDrawXY(22,30,'6',0);
break;
case 7 :Dogs102x6_charDrawXY(22,30,'7',0);
break;
case 8 :Dogs102x6_charDrawXY(22,30,'8',0);
break;
case 9 :Dogs102x6_charDrawXY(22,30,'9',0);
break;
}
switch(ptr[3])
{
case 0 :Dogs102x6_charDrawXY(28,30,'0',0);
break;
case 1 :Dogs102x6_charDrawXY(28,30,'1',0);
break;
case 2 :Dogs102x6_charDrawXY(28,30,'2',0);
break;
case 3 :Dogs102x6_charDrawXY(28,30,'3',0);
break;
case 4 :Dogs102x6_charDrawXY(28,30,'4',0);
break;
case 5 :Dogs102x6_charDrawXY(28,30,'5',0);
break;
case 6 :Dogs102x6_charDrawXY(28,30,'6',0);
break;
case 7 :Dogs102x6_charDrawXY(28,30,'7',0);
break;
case 8 :Dogs102x6_charDrawXY(28,30,'8',0);
break;
case 9 :Dogs102x6_charDrawXY(28,30,'9',0);
break;
}
}
void main(void)
{
WDTCTL = WDTPW+WDTHOLD;//关闭看门狗
Board_init();
Dogs102x6_init();
Dogs102x6_backlightInit();
Dogs102x6_clearScreen();
Dogs102x6_setBacklight(11);
Dogs102x6_setContrast(15);
P6SEL |= BIT6;
ADC12CTL0 = ADC12ON+ADC12SHT0_8+ADC12MSC; //打开ADC12,设置采样保持时间为256个ADC12时钟周期,多次采样转换位使能;
ADC12CTL1 |=ADC12CSTARTADD_6+ADC12SHP+ADC12CONSEQ_2;//使用第六通道,采样信号源自采样定时器,采样时间由采样定时器决定,单通道序列
ADC12MCTL6 |=ADC12INCH_6;//使用通道六
ADC12IE = BIT6; //打开相应通道中断
P1DIR |=BIT0+BIT1;
P1OUT &=~BIT0;
_EINT();
while(1)
{
ADC12CTL0 |= ADC12ENC;//ADC12使能
ADC12CTL0 |= ADC12SC;//启动转换
_bis_SR_register(LPM0_bits);
zhuanhuan(3256);
__no_operation();
}
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
static unsigned char index=0;
Result[index++]=ADC12MEM6; //存入转换结果
if(index==8)
{
unsigned char i;
for(i=0;i>=3;
index=0;
if(Average>=0x7f)
P1OUT =BIT0;
else
P1OUT &=~BIT0;
ADC12CTL0 &=~ADC12ENC; //退出单通道序列转换转换
}
ADC12IFG =0X00;;
_bic_SR_register_on_exit(LPM0_bits);
}