功能
msp430f5529单片机,读取DHT11温湿度,读取adc,oled显示
硬件
//OLED引脚分配 绿色板子
//DO(SCLK)------P4.3
//D1(DATA)------P4.0
//mq135 P6.5
//DHT11 P4.1
部分代码
cpp
unsigned 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 );
}
}
}
}
全部代码
cpp
https://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?tab=BB08J2