/*******************************************************************************
*******************************************************************************/
#include "msp430g2553.h"
#include "OLED_SSD1306.h"
long temp;
long temp1;
void OLED_SSD1306_DisplayVoltage()
{
unsigned char Display_val[5]={0,0,0x2e,0,0};
int display_data_01 = temp1;
WDTCTL=WDTPW+WDTHOLD;
OLED_SSD1306_Init();
while(1)
{
Display_val[0] =display_data_01/100+0x30;
Display_val[1] =(display_data_01%100/10)+0x30;
Display_val[3] =(display_data_01%10)+0x30;
OLED_SSD1306_Display8x16Str(0,0, "I");
OLED_SSD1306_Display8x16Str(0,8, "");
OLED_SSD1306_Display8x16Str(0,16, "_");
OLED_SSD1306_Display8x16Str(0,24, "01:");
OLED_SSD1306_Display8x16Str(0,56, &Display_val[0]);
OLED_SSD1306_Display8x16Str(0,96, "V");
__delay_cycles(10000);
__delay_cycles(10000);
__delay_cycles(10000);
__delay_cycles(10000);
__delay_cycles(10000);
__delay_cycles(10000);
__delay_cycles(10000);
__delay_cycles(10000);
__delay_cycles(10000);
__delay_cycles(10000);
__delay_cycles(10000);
__delay_cycles(10000);
}
}
void ADC_Init()
{
ADC10CTL0&= ~ENC;
ADC10CTL0 = ADC10SHT_3 + ADC10ON + ADC10IE+REFON+SREF_1;
ADC10CTL1|= ADC10SSEL0+INCH_1+ADC10DIV_7+CONSEQ_0+SHS_0; //MCLK做时钟源,通道1
ADC10CTL0|= ENC; //使能转换器
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
_BIC_SR_IRQ(LPM4_bits);
}
void PWM_Init()
{
P1DIR |= BIT6+BIT0;
P1DIR &=~BIT3; //P1.3作为按键输入
P1SEL |= BIT6; //P1.6作为PWM输出
P1IE |= BIT3; // P1.3 interrupt enabled
P1IES |= BIT3; // P1.3 Hi/lo edge
P1REN |= BIT3; // P1.3 pullup
P1OUT|=BIT0; //P1.0作为一个指示灯输出
_EINT();
TACTL = TASSEL_2 + MC_1+ID_3;// MCLK, up mode,适用于高频率
CCR0 = 511;// PWM 周期 =(CCRO+1)/1048576,频率=1.048576MHz/(CCRO+1))
CCTL1 = OUTMOD_7;// CCR1 reset/set
CCR1 = 33;// CCR1 PWM 占空比% = (CCR1+1)/(CCRO+1)
for (;;)
{
_BIS_SR(GIE); // 进入 LPM3
_NOP();
}
}
#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
P1OUT ^= BIT0; //每读一次中断,指示灯状态取反
TACCR1=TACCR1+1 ;
if(TACCR1==49)
TACCR1=33;
P1IFG &= ~BIT3; // P1.3 IFG cleared
}
void main(void)
{
WDTCTL=WDTPW+WDTHOLD;
ADC_Init();
PWM_Init();
while(1)
{
ADC10CTL0 |= ENC+ADC10SC; //开启转换
_BIC_SR(CPUOFF+GIE);
temp=ADC10MEM;
temp1=temp*250/1023;
OLED_SSD1306_DisplayVoltage();
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>