Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 00003 DigitalOut myled(LED1); 00004 Serial pc(USBTX, USBRX); // tx, rx 00005 AnalogIn ain(A0); //is ADC0_0: must be channel 0 of ADC0 or ADC1 00006 00007 #define ADCn_INSEL_TEMPERATURE (0x3) 00008 #define SYSCON_PDRUNCFG_TS_PD (1 << 18) 00009 #define SYSCON_PDRUNCFG_IREF_PD (1 << 17) 00010 00011 int main() { 00012 pc.printf("Starting program...\r\n"); 00013 00014 //Enable temperature sensor and internal voltage reference, see um chapter 31 00015 LPC_SYSCON->PDRUNCFG &= ~(SYSCON_PDRUNCFG_TS_PD | SYSCON_PDRUNCFG_IREF_PD); 00016 00017 //Select source for channel 0: temperature sensor 00018 LPC_ADC0->INSEL = ADCn_INSEL_TEMPERATURE; 00019 00020 while(1) { 00021 unsigned short raw = ain.read_u16(); 00022 pc.printf("Raw u16 value %u\r\n", raw); 00023 pc.printf("Raw 12 Bit value %u\r\n", (raw >> 4)); 00024 float value = ((float)raw) / (float) 0xffff; 00025 pc.printf("Float value %f\r\n", value); 00026 pc.printf("Read value %f mV\r\n", value * 3300.0f); 00027 float temperature = -(((value * 3300.0f) - 577.3f) / 2.29f); 00028 pc.printf("Read temperature (about) %f deg C\r\n", temperature); 00029 myled = !myled; 00030 wait(1); 00031 } 00032 }
Generated on Thu Jul 28 2022 05:30:59 by
1.7.2