team app1
/
HelloWorld
test
Fork of HelloWorld by
Diff: main.cpp
- Revision:
- 22:706708bc4c1a
- Parent:
- 21:74482f23c8fe
- Child:
- 23:262e3e171aaf
diff -r 74482f23c8fe -r 706708bc4c1a main.cpp --- a/main.cpp Fri Sep 01 17:41:34 2017 +0000 +++ b/main.cpp Sun Sep 03 17:06:51 2017 +0000 @@ -1,52 +1,66 @@ #include "mbed.h" -#include "MMA8452Q.h" +//#include "MMA8452Q.h" -Serial pc(USBTX, USBRX); // tx, rx -SPI accel(p11,p12,p13); -DigitalOut cs(p14); +//Serial pc(USBTX, USBRX); // tx, rx +//SPI accel(p11,p12,p13); +//DigitalOut cs(p14); // Communication I2C //I2C comI2C(p9,p10); // sda, scl + +void UARTInit() +{ + uint16_t usFdiv; + + // Power up the UART3 it's disabled on powerup. + LPC_SC->PCONP |= (1 << 25); + + // Enable the pins on the device to use UART3 + LPC_PINCON->PINSEL1 |= (3 << 18); /* Pin P0.25 used as TXD0 (Com0) */ + LPC_PINCON->PINSEL1 |= (3 << 20); /* Pin P0.26 used as RXD0 (Com0) */ + + // Setup the PCLK for UART3 + LPC_SC->PCLKSEL1 &= ~(3 << 18); // Clean all to 0 + LPC_SC->PCLKSEL1 |= (1 << 18); // PCLK = CCLK + + // Word select 8-bit character length and set DLAB + LPC_UART3->LCR = 0x83; // 0000 0000 1000 0011 + + usFdiv = (SystemCoreClock / (16*9600)); + LPC_UART3->DLM = usFdiv / 256; + LPC_UART3->DLL = usFdiv % 256; + + //LPC_UART3->DLM = ((SystemCoreClock / (16*9600))/256); + //LPC_UART3->DLL = ((SystemCoreClock / (16*9600))%256); + + // Enable and reset UART3 FIFOs. + LPC_UART3->FCR = 0x7; + + // Enable the interrupt + // NVIC_EnableIRQ(UART3_IRQn); + + // Init the UART3 RX interrupt + // LPC_UART3->IER = 0x01; + + // Clear DLAB + LPC_UART3->LCR &= ~(1 << 7); + + //pc.printf("system clock : %d", SystemCoreClock); +} + +char UART3Transmit(int out) +{ + LPC_UART3 -> THR = out; + while(! (LPC_UART3->LSR & (0x01 << 0x06))); + + return 1; +} + int main() { - - // Power up the UART3 it's disabled on powerup. - LPC_SC->PCONP |= (1UL << 25); - - // Setup the PCLK for UART3 - // LPC_SC->PCLKSEL1 &= ~(3UL << 18); // Clean - LPC_SC->PCLKSEL1 |= (1UL << 18); // PCLK = CCLK - - // Setup the baud rate for 9600 - LPC_UART3->LCR = 0x80; // LPC_UART3->LCR |= (1UL << 7); - LPC_UART3->DLM = 0x2; - LPC_UART3->DLL = 0x71; - LPC_UART3->LCR = 0x3; // 8-bit character length - - // Enable the pins on the device to use UART3 - LPC_PINCON->PINSEL0 |= (3UL << 18); - LPC_PINCON->PINSEL0 |= (3UL << 20); + UARTInit(); - // Enable and reset UART3 FIFOs. - LPC_UART3->FCR = 0x7; - - // Enable the interrupt - NVIC_EnableIRQ(UART3_IRQn); - - // Init the UART3 RX interrupt - LPC_UART3->IER = 0x01; - - LPC_UART3->LCR &= ~(1UL << 7); - - LPC_UART3->THR = 7; - - /* - while(LPC_UART3->THRE = 0) - { - - } - */ - + UART3Transmit(7); /* float x, y, z ; @@ -146,16 +160,18 @@ wait(1); } }*/ + /* Serial pc(USBTX, USBRX); // tx, rx -Serial mc(p13,p14); +Serial mc(p9,p10); int main() { - int nombre = 0; + int nombre; pc.printf("Entrez un nombre de 4 chiffres : "); pc.scanf("%d", &nombre); pc.printf("Votre numero entrez est le : %d", nombre); - mc.printf(nombre); + //mc.printf(nombre); + mc.putc(nombre); } */