This Program Demonstrate how to make LPC1768 ADC measure the analog voltage and report it to through the USB uart of mbed.
main.cpp@0:c0f5fc067a00, 2010-09-30 (annotated)
- Committer:
- boseji
- Date:
- Thu Sep 30 15:36:20 2010 +0000
- Revision:
- 0:c0f5fc067a00
- Child:
- 1:dd22d26c3a63
First version with Power Save
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
boseji | 0:c0f5fc067a00 | 1 | /** |
boseji | 0:c0f5fc067a00 | 2 | * \brief ADC Processing, Serial Comm, Timers, Button Inputs, Analog Output, FAT File systems |
boseji | 0:c0f5fc067a00 | 3 | * |
boseji | 0:c0f5fc067a00 | 4 | * \version 0.0 |
boseji | 0:c0f5fc067a00 | 5 | * |
boseji | 0:c0f5fc067a00 | 6 | * \author boseji (http://m8051.blogspot.com) |
boseji | 0:c0f5fc067a00 | 7 | * |
boseji | 0:c0f5fc067a00 | 8 | * \note |
boseji | 0:c0f5fc067a00 | 9 | * Copyright (c) 2010, boseji |
boseji | 0:c0f5fc067a00 | 10 | * released under MIT license http://mbed.org/licence/mit |
boseji | 0:c0f5fc067a00 | 11 | * |
boseji | 0:c0f5fc067a00 | 12 | */ |
boseji | 0:c0f5fc067a00 | 13 | ////////////////////////////////////////////////// |
boseji | 0:c0f5fc067a00 | 14 | // Include Files |
boseji | 0:c0f5fc067a00 | 15 | #include "mbed.h" |
boseji | 0:c0f5fc067a00 | 16 | #include "PowerControl.h" |
boseji | 0:c0f5fc067a00 | 17 | #include "EthernetPowerControl.h" |
boseji | 0:c0f5fc067a00 | 18 | ////////////////////////////////////////////////// |
boseji | 0:c0f5fc067a00 | 19 | //Pin Defines |
boseji | 0:c0f5fc067a00 | 20 | DigitalOut sysled(LED1); //System Indicator |
boseji | 0:c0f5fc067a00 | 21 | DigitalOut ind1(LED2); |
boseji | 0:c0f5fc067a00 | 22 | DigitalOut ind2(LED3); |
boseji | 0:c0f5fc067a00 | 23 | DigitalOut ind3(LED4); |
boseji | 0:c0f5fc067a00 | 24 | |
boseji | 0:c0f5fc067a00 | 25 | AnalogIn Sense1(p15); //Sensor 1 |
boseji | 0:c0f5fc067a00 | 26 | AnalogIn Sense2(p16); //Sensor 2 |
boseji | 0:c0f5fc067a00 | 27 | AnalogIn Sense3(p17); //Sensor 3 |
boseji | 0:c0f5fc067a00 | 28 | AnalogIn Sense4(p19); //Sensor 4 |
boseji | 0:c0f5fc067a00 | 29 | AnalogIn Sense5(p20); //Sensor 5 |
boseji | 0:c0f5fc067a00 | 30 | |
boseji | 0:c0f5fc067a00 | 31 | AnalogOut Voc(p18); |
boseji | 0:c0f5fc067a00 | 32 | |
boseji | 0:c0f5fc067a00 | 33 | Ticker t1;//Timer |
boseji | 0:c0f5fc067a00 | 34 | |
boseji | 0:c0f5fc067a00 | 35 | //Configure the PC Serial Port for CDC USB |
boseji | 0:c0f5fc067a00 | 36 | Serial pc(USBTX, USBRX); // tx, rx |
boseji | 0:c0f5fc067a00 | 37 | ////////////////////////////////////////////////// |
boseji | 0:c0f5fc067a00 | 38 | // Function Declarations |
boseji | 0:c0f5fc067a00 | 39 | void tint1( void ); |
boseji | 0:c0f5fc067a00 | 40 | ////////////////////////////////////////////////// |
boseji | 0:c0f5fc067a00 | 41 | // main Program |
boseji | 0:c0f5fc067a00 | 42 | int main() { |
boseji | 0:c0f5fc067a00 | 43 | |
boseji | 0:c0f5fc067a00 | 44 | unsigned short usCurrentValue; |
boseji | 0:c0f5fc067a00 | 45 | //Power Down the Unused Ethernet PHY |
boseji | 0:c0f5fc067a00 | 46 | EMAC_Init(); |
boseji | 0:c0f5fc067a00 | 47 | PHY_EnergyDetect_Disable(); |
boseji | 0:c0f5fc067a00 | 48 | PHY_PowerDown(); |
boseji | 0:c0f5fc067a00 | 49 | |
boseji | 0:c0f5fc067a00 | 50 | //Configure the Fastest Baud Rate |
boseji | 0:c0f5fc067a00 | 51 | pc.baud(115200); |
boseji | 0:c0f5fc067a00 | 52 | |
boseji | 0:c0f5fc067a00 | 53 | printf("Aum Sri Ganeshay Namh !!\n"); |
boseji | 0:c0f5fc067a00 | 54 | |
boseji | 0:c0f5fc067a00 | 55 | //Configure the Timer |
boseji | 0:c0f5fc067a00 | 56 | t1.attach(&tint1,0.8); |
boseji | 0:c0f5fc067a00 | 57 | |
boseji | 0:c0f5fc067a00 | 58 | //Say the System is Ready to Run |
boseji | 0:c0f5fc067a00 | 59 | sysled = 1; |
boseji | 0:c0f5fc067a00 | 60 | |
boseji | 0:c0f5fc067a00 | 61 | //Final Infinite Loop |
boseji | 0:c0f5fc067a00 | 62 | while (1) { |
boseji | 0:c0f5fc067a00 | 63 | usCurrentValue = (Sense1.read_u16()&0xFFF); |
boseji | 0:c0f5fc067a00 | 64 | ind3 = !ind3; |
boseji | 0:c0f5fc067a00 | 65 | wait(0.2); |
boseji | 0:c0f5fc067a00 | 66 | printf("\n ADC Val : %f Volts = %d (Decimal Reading)",(usCurrentValue*3.3/4095),usCurrentValue); |
boseji | 0:c0f5fc067a00 | 67 | } |
boseji | 0:c0f5fc067a00 | 68 | } |
boseji | 0:c0f5fc067a00 | 69 | ////////////////////////////////////////////////// |
boseji | 0:c0f5fc067a00 | 70 | // Functions |
boseji | 0:c0f5fc067a00 | 71 | |
boseji | 0:c0f5fc067a00 | 72 | // Interrupt for the Timer |
boseji | 0:c0f5fc067a00 | 73 | void tint1( void ) { |
boseji | 0:c0f5fc067a00 | 74 | //printf("\n Aum "); |
boseji | 0:c0f5fc067a00 | 75 | ind2 = !ind2; |
boseji | 0:c0f5fc067a00 | 76 | |
boseji | 0:c0f5fc067a00 | 77 | } |