功能
声音越大,亮的灯越多。
oled显示出当前的声音大小。
硬件接线
//OLED----MSP430
//VCC-----3.3V
//GND-----GND
//D0------P3.2
//D1------P3.0
//RES-----P2.0
//DC------P2.2
//CS------P8.1
led
P4八个引脚
adc
P6.0
部分代码
_EINT();while (1){adok_ifg = 1; /* 转换结束后变成0 */ADC12CTL0 |= ADC12SC; // Sampling opendelay_ms(500);while (adok_ifg == 1); /* 等待装换结束 */fute = adcvalue * 0.00805;xianshi[0] = fute % 100 / 10 + '0';xianshi[1] = '.';xianshi[2] = fute % 10 + '0';xianshi[3] = 'V';xianshi[4] = 0;OLED_ShowString(0, 0, xianshi);xianshi[0] = adcvalue % 10000 / 1000 + '0';xianshi[1] = adcvalue % 1000 / 100 + '0';xianshi[2] = adcvalue % 100 / 10 + '0';xianshi[3] = adcvalue % 10 + '0';xianshi[4] = 'X';xianshi[5] = 0;OLED_ShowString(0, 2, xianshi);if (adcvalue <= min_YIN)adcvalue = min_YIN;if (adcvalue > max_YIN)adcvalue = max_YIN;adcvalue = adcvalue - min_YIN;temp1 = max_YIN - min_YIN;duan = temp1 / 8;if (adcvalue > duan * 7){P4OUT = 0X00;}else if (adcvalue > duan * 6){P4OUT = BIT7;}else if (adcvalue > duan * 5){P4OUT = BIT7 + BIT6;}else if (adcvalue > duan * 4){P4OUT = BIT7 + BIT6 + BIT5;}else if (adcvalue > duan * 3){P4OUT = BIT7 + BIT6 + BIT5 + BIT4;}else if (adcvalue > duan * 2){P4OUT = BIT7 + BIT6 + BIT5 + BIT4 + BIT3;}else if (adcvalue > duan * 1){P4OUT = BIT7 + BIT6 + BIT5 + BIT4 + BIT3 + BIT2;}else if (adcvalue > 50){P4OUT = BIT7 + BIT6 + BIT5 + BIT4 + BIT3 + BIT2 + BIT1;}else{P4OUT = 0XFF;}temp1 = max_YIN - min_YIN;temp2 = (float) adcvalue / (float) temp1 * 300;temp3 = temp2;temp1 = 210 + temp3;CCR1 = temp1; //设置为210到510xianshi[0] = 'P';xianshi[1] = 'W';xianshi[2] = 'M';xianshi[3] = temp1 % 10000 / 1000 + '0';xianshi[4] = temp1 % 1000 / 100 + '0';xianshi[5] = temp1 % 100 / 10 + '0';xianshi[6] = temp1 % 10 + '0';xianshi[7] = 0;OLED_ShowString(0, 4, xianshi);}
}// ADC12 interrupt service routine
#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{adcvalue = ADC12MEM0;adok_ifg = 0;}
全部代码
https://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?u=bdf8eeb84961492ba2b62f7bfee641ea&tab=BB08J2