
20x4 LCD with SRM32F407
main.cpp@3:15d08fd609ec, 2020-01-13 (annotated)
- Committer:
- suntopbd
- Date:
- Mon Jan 13 04:36:25 2020 +0000
- Revision:
- 3:15d08fd609ec
- Parent:
- 2:ad0b044d0a10
ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 1:7418a52375a0 | 1 | // Hello World! for the TextLCD |
simon | 1:7418a52375a0 | 2 | |
simon | 0:334327d1a416 | 3 | #include "mbed.h" |
simon | 0:334327d1a416 | 4 | #include "TextLCD.h" |
simon | 0:334327d1a416 | 5 | |
suntopbd | 3:15d08fd609ec | 6 | TextLCD lcd(PC_15, PC_13, PC_14, PE_6, PE_4, PE_2,TextLCD::LCD20x4); // rs, e, d4-d7 |
suntopbd | 3:15d08fd609ec | 7 | AnalogIn adcPB0(PB_0); |
suntopbd | 3:15d08fd609ec | 8 | AnalogIn adcPB1(PB_1); |
suntopbd | 3:15d08fd609ec | 9 | AnalogOut dacPA5(PA_5); |
suntopbd | 3:15d08fd609ec | 10 | DigitalIn buttonPA0 (PA_0); |
suntopbd | 3:15d08fd609ec | 11 | DigitalIn extbutton1PE5 (PE_5); |
suntopbd | 3:15d08fd609ec | 12 | DigitalIn extbutton2PE3 (PE_3); |
suntopbd | 3:15d08fd609ec | 13 | DigitalOut rLED(PD_14); // on board red LED, DO |
suntopbd | 3:15d08fd609ec | 14 | DigitalOut bLED(PD_15); // on board blue LED. DO |
suntopbd | 3:15d08fd609ec | 15 | DigitalOut gLED(PD_12); // on board green LED, DO |
suntopbd | 3:15d08fd609ec | 16 | DigitalOut oLED(PD_13); // on board orange LED, DO |
suntopbd | 3:15d08fd609ec | 17 | |
suntopbd | 3:15d08fd609ec | 18 | DigitalOut exRef(PE_7); // on board orange LED, DO |
suntopbd | 3:15d08fd609ec | 19 | |
suntopbd | 3:15d08fd609ec | 20 | |
suntopbd | 3:15d08fd609ec | 21 | |
suntopbd | 3:15d08fd609ec | 22 | uint32_t adcval=0; |
suntopbd | 3:15d08fd609ec | 23 | uint16_t val=0; |
suntopbd | 3:15d08fd609ec | 24 | |
simon | 0:334327d1a416 | 25 | |
simon | 0:334327d1a416 | 26 | int main() { |
suntopbd | 3:15d08fd609ec | 27 | dacPA5=0.0f; |
suntopbd | 3:15d08fd609ec | 28 | extbutton1PE5.mode(PullUp); |
suntopbd | 3:15d08fd609ec | 29 | extbutton2PE3.mode(PullUp); |
suntopbd | 3:15d08fd609ec | 30 | exRef=1; |
suntopbd | 3:15d08fd609ec | 31 | |
suntopbd | 3:15d08fd609ec | 32 | while(1) |
suntopbd | 3:15d08fd609ec | 33 | { |
suntopbd | 3:15d08fd609ec | 34 | lcd.cls(); |
suntopbd | 3:15d08fd609ec | 35 | lcd.printf("mbed with STM32F407G"); |
suntopbd | 3:15d08fd609ec | 36 | lcd.printf(" !! It Worked !!\n"); |
suntopbd | 3:15d08fd609ec | 37 | if(dacPA5<1.00f) |
suntopbd | 3:15d08fd609ec | 38 | dacPA5 = dacPA5+0.002442f; |
suntopbd | 3:15d08fd609ec | 39 | adcval=0; |
suntopbd | 3:15d08fd609ec | 40 | for(int i=0;i<4096;i++) |
suntopbd | 3:15d08fd609ec | 41 | { |
suntopbd | 3:15d08fd609ec | 42 | adcval= adcval + 4095*adcPB1.read_u16()/65535; // 12 bit value |
suntopbd | 3:15d08fd609ec | 43 | } |
suntopbd | 3:15d08fd609ec | 44 | val=adcval/4096; |
suntopbd | 3:15d08fd609ec | 45 | lcd.printf(" ADC on PB1: %d\n", val); |
suntopbd | 3:15d08fd609ec | 46 | lcd.printf("AREF Volts: %f",(2.9464*val/4095)); |
suntopbd | 3:15d08fd609ec | 47 | wait(.25); |
suntopbd | 3:15d08fd609ec | 48 | rLED =extbutton1PE5.read(); |
suntopbd | 3:15d08fd609ec | 49 | bLED =extbutton2PE3.read(); |
suntopbd | 3:15d08fd609ec | 50 | gLED =!extbutton1PE5.read(); |
suntopbd | 3:15d08fd609ec | 51 | oLED =!extbutton2PE3.read(); |
suntopbd | 3:15d08fd609ec | 52 | while(buttonPA0) |
suntopbd | 3:15d08fd609ec | 53 | {} |
suntopbd | 3:15d08fd609ec | 54 | |
suntopbd | 3:15d08fd609ec | 55 | } |
simon | 0:334327d1a416 | 56 | } |