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.
Revision 11:09317efe9bb5, committed 2017-09-06
- Comitter:
- ThierryLeonard
- Date:
- Wed Sep 06 03:46:20 2017 +0000
- Parent:
- 10:2836530d9a5e
- Commit message:
- Beautify LOL still ugly
Changed in this revision
--- a/Accelerometre.cpp Wed Sep 06 01:29:41 2017 +0000
+++ b/Accelerometre.cpp Wed Sep 06 03:46:20 2017 +0000
@@ -1,6 +1,11 @@
#include "Accelerometre.h"
-
+namespace
+{
+ const double PI = 3.14159265359;
+ const int WRITE_DATA = 0x38;
+ const int READ_DATA = 0x39;
+}
Accelerometre::Accelerometre():i2c(p28,p27),pc(USBTX, USBRX),acc(p28, p27, 40000){
acc.setBitDepth(MMA8452::BIT_DEPTH_12);
@@ -32,22 +37,6 @@
return (angle*180/ PI);
}
-
-//int Accelerometre::readSingleByte(int regis){
-// int c;
-// pc.printf("Reading single byte\n");
-// i2c.start();
-// int a=i2c.write(WRITE_DATA); // A write to device
-// i2c.write(regis); // Register to read from (acceleration in X)
-// i2c.start(); // Need to send start condition here
-// i2c.write(READ_DATA); // tell devide you want to read
-// c=i2c.read(0);
-// i2c.stop();
-// pc.printf("value is %d\n", c);
-// pc.printf("end\n");
-// return c;
-// }
-
void Accelerometre::writeByte(int regis,int data){
pc.printf("Reading single byte\n");
--- a/Accelerometre.h Wed Sep 06 01:29:41 2017 +0000
+++ b/Accelerometre.h Wed Sep 06 03:46:20 2017 +0000
@@ -5,18 +5,16 @@
#include "MMA8452.h"
class Accelerometre{
-
- double const PI = 3.14159265359;
- int const WRITE_DATA = 0x38;
- int const READ_DATA = 0x39;
- MMA8452 acc;
+
+
I2C i2c;
Serial pc;
+ MMA8452 acc;
+
public:
void writeByte(int Regist,int data);
void readxyzAngle(double *angle);
- int readMultiByte(int regist);
Accelerometre();
private:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CommUART.cpp Wed Sep 06 03:46:20 2017 +0000
@@ -0,0 +1,43 @@
+#include "CommUART.h"
+
+ CommUART3::CommUART3()
+ {
+ // Power
+ LPC_SC->PCONP |= (1 << 25) ;//0x400F C0C4 -> PCUART3
+ // Peripheral clock selection -> CCLK
+
+ // DLab enable divide latch
+ LPC_UART3->LCR |= (1 << 7);
+
+ //Default Baud rate of 9600 in serial segment
+ // MSB of baud rate divisor
+ LPC_UART3->DLM = 0x2;
+ // MLB of baud rate divisor
+ LPC_UART3->DLL = 0x71;
+
+ // want 8-bit characters
+ LPC_UART3->LCR = 3;
+
+ // Enable FIFO
+ LPC_UART3->FCR = 1;
+
+ // PINSEL0 1:0 : mode p9 ->
+ LPC_PINCON->PINSEL0 &= ~3;
+ LPC_PINCON->PINSEL0 |= 2;
+ LPC_SC->PCLKSEL1 &= ~ (3 << 18 ) ; // clear the bits 18-19
+ LPC_SC->PCLKSEL1 |= 1 << 18 ;//0x400F C1AC -> PCLK_UART3 =01
+
+ }
+
+ void CommUART3::write(char ch)
+ {
+ LPC_UART3->TER = 0x80;
+ LPC_UART3->THR = ch;
+ }
+ void CommUART3::write(char* ch, int length, char* unused, int unused2)
+ {
+ for(int i = 0 ; i < length ; i ++)
+ {
+ write(ch[i]);
+ }
+ }
\ No newline at end of file
--- a/CommUART.h Wed Sep 06 01:29:41 2017 +0000
+++ b/CommUART.h Wed Sep 06 03:46:20 2017 +0000
@@ -8,53 +8,12 @@
class CommUART3
{
public:
- CommUART3()
- {
- // Power
- LPC_SC->PCONP |= (1 << 25) ;//0x400F C0C4 -> PCUART3
- // Peripheral clock selection -> CCLK
-
- // DLab enable divide latch
- LPC_UART3->LCR |= (1 << 7);
-
- //Default Baud rate of 9600 in serial segment
- // MSB of baud rate divisor
- LPC_UART3->DLM = 0x2;
- // MLB of baud rate divisor
- LPC_UART3->DLL = 0x71;
-
- // want 8-bit characters
- LPC_UART3->LCR = 3;
-
- // Enable FIFO
- LPC_UART3->FCR = 1;
-
- // PINSEL0 1:0 : mode p9 ->
- LPC_PINCON->PINSEL0 &= ~3;
- LPC_PINCON->PINSEL0 |= 2;
- LPC_SC->PCLKSEL1 &= ~ (3 << 18 ) ; // clear the bits 18-19
- LPC_SC->PCLKSEL1 |= 1 << 18 ;//0x400F C1AC -> PCLK_UART3 =01
+ //Initialyze UART3 on pin nine
+ CommUART3();
- }
-
- void write(char ch)
- {
- LPC_UART3->TER = 0x80;
- Serial pc(USBTX, USBRX);
- pc.printf("%c", ch);
- LPC_UART3->THR = ch;
- }
- void write(char* ch, int length, char* unused, int unused2)
- {
- Serial pc(USBTX, USBRX);
- pc.printf("rip");
- for(int i = 0 ; i < length ; i ++)
- {
- write(ch[i]);
- }
- }
-
-
+ void write(char ch);
+ // match signature of spi write
+ void write(char* ch, int length, char* unused, int unused2);
private:
};
--- a/MainEvr.cpp Wed Sep 06 01:29:41 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-#include "Accelerometre.h"
-#include "Afficheur.h"
-
-Serial pc(USBTX, USBRX);
-int main() {
-
-
-
- Afficheur afficheur;
- Accelerometre acc;
-
- double angle = 0;
-
- while(true){
-
- acc.readxyzAngle(&angle);
- pc.printf("angle is : %lf\r\n",angle);
-
-
-
- char c1[10];
- char c2[4];
-
- sprintf(c1 , "%4f" , angle);
- int virgule;
- int j =0;
- for(int i =0;i<4;i++){
- if(c1[j] == '.'){
- virgule = 1 <<j-1;
- i--;
- j++;
- continue;
- }
- c2[i] = c1[j];
- j++;
-
- }
-
- pc.printf("virg= %d",virgule);
- afficheur.write(c2,4, virgule);
-
- pc.printf("test");
- wait(0.45);
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Sep 06 03:46:20 2017 +0000
@@ -0,0 +1,45 @@
+#include "Accelerometre.h"
+#include "Afficheur.h"
+
+Serial pc(USBTX, USBRX);
+int main() {
+
+
+
+ Afficheur afficheur;
+ Accelerometre acc;
+
+ double angle = 0;
+
+ while(true){
+
+ acc.readxyzAngle(&angle);
+ pc.printf("angle is : %lf\r\n",angle);
+
+
+
+ char c1[10];
+ char c2[4];
+
+ sprintf(c1 , "%4f" , angle);
+ int virgule;
+ int j =0;
+ for(int i =0;i<4;i++){
+ if(c1[j] == '.'){
+ virgule = 1 <<j-1;
+ i--;
+ j++;
+ continue;
+ }
+ c2[i] = c1[j];
+ j++;
+
+ }
+
+ pc.printf("virg= %d",virgule);
+ afficheur.write(c2,4, virgule);
+
+ pc.printf("test");
+ wait(0.45);
+ }
+}
--- a/maint.cpp Wed Sep 06 01:29:41 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-//#include "mbed.h"
-//#include "Afficheur.h"
-//
-//
-//Serial pc(USBTX, USBRX); // tx, rx
-//
-//Afficheur afficheur;
-//
-//int main() {
-// while(1)
-// {
-// if(pc.readable())
-// {
-// afficheur.write(pc.getc());
-// }
-//
-// }
-//
-//}
