#include "msp430g2553.h"
#include "OLED_SSD1306.h"
long temp;
long display_data_01;
void OLED_SSD1306_DisplayVoltage()
{
unsigned char Display_val[5]={0,0,0x2e,0,0};
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, "U");
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 ADC10_Init()
{
P1SEL&=0x02;
ADC10CTL0=ADC10SHT_1+ADC10ON+SREF_1+REF2_5V+REFON+MSC;
ADC10CTL1=INCH_1+ADC10DIV_1+CONSEQ_2;
ADC10AE0|=BIT1;
}
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)
}
#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;
ADC10_Init();
PWM_Init();
while(1)
{
ADC10CTL0 |= ENC+ADC10SC;
temp=ADC10MEM;
display_data_01=temp*250/1023;
OLED_SSD1306_DisplayVoltage();
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>