msp430f5529单片机,读取DHT11温湿度,读取adc,oled显示
//OLED引脚分配 绿色板子
//DO(SCLK)------P4.3
//D1(DATA)------P4.0
//RES-----------P3.7
//DC------------P8.2
//CS------------P8.1
//mq135 P6.5
//DHT11 P4.1
cppunsigned int adcsignal;
unsigned char disp[15];
unsigned char count = 0;
void main( void )
{
unsigned char t = 0;
WDTCTL = WDTPW + WDTHOLD; /* Stop WDT */
initClock();
OLED_Init();
OLED_ShowString( 0, 0, "DHT11:" );
OLED_ShowString( 0, 4, "mq135:" );
while ( 1 )
{
delay_ms( 10 );
t = (t + 1) % 30;
if ( t == 1 ) /* 30 个10ms执行一次 */
{
if ( receive_init() == 1 )
{
/* 存入数组 */
count = 0;
disp[count++] = ' ';
disp[count++] = ' ';
disp[count++] = humdh % 100 / 10 + '0';
disp[count++] = humdh % 10 / 1 + '0';
disp[count++] = '%';
disp[count++] = 'R';
disp[count++] = 'H';
disp[count++] = ' ';
disp[count++] = ' ';
disp[count++] = temph % 100 / 10 + '0';
disp[count++] = temph % 10 / 1 + '0';
disp[count++] = 'C';
disp[count++] = 0;
/* 显示屏上显示温湿度字符串 */
OLED_ShowString( 0, 2, disp );
ADC12CTL0 |= ADC12SC; /* Start sampling/conversion */
while ( (ADC12IFG & BIT5) == 0 )
; /* MEM5触发IFG5 意味着有了新的转换结果 */
adcsignal = ADC12MEM5;
adcsignal = (unsigned int ) ( ( (float) adcsignal) * 3.3 * 100 / 4096); /* 换算到伏特 并乘以100 */
count = 0;
disp[count++] = adcsignal % 1000 / 100 + '0';
disp[count++] = '.';
disp[count++] = adcsignal % 100 / 10 + '0';
disp[count++] = adcsignal % 10 / 1 + '0';
disp[count++] = 'V';
disp[count++] = 0;
OLED_ShowString( 0, 6, disp );
}
}
}
}
cpphttps://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?tab=BB08J2
本文作者:Dong
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!