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.
Fork of Thread_Communication_V4_fortest by
Revision 0:cb3a5c15b01e, committed 2017-12-12
- Comitter:
- benparkes
- Date:
- Tue Dec 12 17:05:59 2017 +0000
- Child:
- 1:bca9993a0df3
- Commit message:
- Working No Mail que
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BMP280.lib Tue Dec 12 17:05:59 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/charly/code/BMP280/#d22ecbef9b90
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD.cpp Tue Dec 12 17:05:59 2017 +0000
@@ -0,0 +1,150 @@
+#include "mbed.h"
+
+#include "LCD.h"
+#define busy_mask 0x8000
+
+
+LCD::LCD(PinName RS, PinName E, PinName d4, PinName d5,
+ PinName d6, PinName d7) : _RS(RS),
+ _E(E), _DBUS(d4, d5, d6, d7) {
+
+ _E = 0;
+ _RS = 0; // command mode
+
+ wait(0.015); // Wait 15ms to ensure powered up
+
+ // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
+
+ wait(0.015); // Wait 15ms to ensure powered up
+
+ for (int i=0; i<3; i++) {
+ DATA(0x30, CMD);
+ wait(0.00164); // this command takes 1.64ms, so wait for it
+ }
+ DATA(0x02, CMD); // 4-bit mode
+ wait(0.000040f); // most instructions take 40us
+
+ DATA(0x28,CMD); // Function set 001 BW N F - -
+ DATA(0x0C,CMD);
+ DATA(0x06,CMD); // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes
+ Clear();
+ DATA(0x01,CMD); // cls, and set cursor to 0
+ wait(0.00164f); // This command takes 1.64 ms
+ Write("Constructed");
+}
+
+
+
+
+/*int main(){
+ //(PF_13, PE_9, PF_14, PF_15)
+ //(PF_15, PF_14, PE_9,PF_13)
+ LCD_DBUS = new BusInOut(PF_13, PE_9, PF_14, PF_15) ;
+ LCD_Init();
+ while(1){
+ write_string("Hi");
+ wait(0.1);
+ }
+ }
+*/
+// Initialise LCD Pins //
+/*void LCD_Init(void){
+ LCD_E = 0;; //clear enable
+ LCD_RW = 0; // write
+ LCD_RS = 0; // command
+
+ wait_ms(3); //delay for LCD to initialise.
+
+ LCD_DATA(0x28,CMD); //set to 4 bit interface, 2 line and 5*8 font
+ LCD_DATA(0x0f,CMD); //cursor on, cursor position blink
+ LCD_DATA(0x10,CMD);
+ LCD_CLR; //clear display
+ LCD_DATA(0x06,CMD); //move cursor right after write
+ LCD_HOME; //return home
+
+ LCD_E = 1;
+ LCD_RS = 0; // command mode
+ LCD_RW = 0;
+ wait(0.015); // Wait 15ms to ensure powered up
+
+ for (int i=0; i<3; i++) {
+ LCD_DATA(0x03, TXT);
+ wait(0.00164); // this command takes 1.64ms, so wait for it
+ }
+ LCD_DATA(0x02, TXT); // 4-bit mode
+ wait(0.000040f); // most instructions take 40us
+
+ LCD_DATA(0x28,CMD); // Function set 001 BW N F - -
+ LCD_DATA(0x0C,CMD);
+ LCD_DATA(0x06,CMD); // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes
+ LCD_DATA(0x01,CMD); // cls, and set cursor to 0
+ wait(0.00164f); // This command takes 1.64 ms
+}*/
+/*---------------------------------------------------------------------*/
+void LCD::Clear(void){
+ DATA(CLEAR,CMD);
+ }
+
+void LCD::RowSelect(int row){
+ switch(row){
+ case 0:
+ DATA(LINE1,CMD);
+ break;
+ case 1:
+ DATA(LINE2,CMD);
+ break;
+ default:
+ DATA(LINE1,CMD);
+ break;
+ }
+ }
+
+void LCD::Busy(void)
+{
+ wait_ms(1);
+}
+/*---------------------------------------------------------------------*/
+void LCD::DATA(char data,char type){
+
+ Busy(); //TEST LCD FOR BUSY
+
+ _DBUS = (data>>4);
+
+ wait(0.00040f); // most instructions take 40us
+
+ if(type == CMD)
+ {
+ _RS = 0; //COMMAND MODE
+ }
+ else
+ {
+ _RS = 1; //CHARACTER/DATA MODE
+ }
+ wait(0.00040f);
+
+ _E = 1; //ENABLE LCD DATA LINE
+ wait(0.00040f); // most instructions take 40us
+ _E = 0; //DISABLE LCD DATA LINE
+
+ _DBUS = 0;
+
+ _DBUS = (data);
+
+ _E = 1; //ENABLE LCD DATA LINE
+ wait(0.00040f); // most instructions take 40us
+ _E = 0; //DISABLE LCD DATA LINE
+}
+/*---------------------------------------------------------------------*/
+void LCD::Write(char text[16]){
+ int i = 0;
+
+
+ while((text[i] != 0))
+ {
+
+ char character = text[i];
+ DATA (character,TXT); // Write text "a" to the LCD
+
+ i++;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD.h Tue Dec 12 17:05:59 2017 +0000
@@ -0,0 +1,33 @@
+#ifndef MBED_LCD_H
+#define MBED_LCD_H
+
+
+#define CMD 0
+#define TXT 1
+#define CLEAR 1
+#define HOME 2
+#define READ 1
+#define WRITE 0
+#define LEFT 0
+#define RIGHT 1
+
+#define LINE1 0x80 // Start address of first line
+#define LINE2 0xC0 // Start address of second line
+
+#define LCD_CLR (LCD_DATA(CLEAR,CMD))
+#define LCD_HOME (LCD_DATA(HOME,CMD))
+
+class LCD{
+public:
+LCD(PinName RS, PinName E, PinName d4, PinName d5, PinName d6, PinName d7);
+void Clear(void);
+void Write(char text[16]);
+void RowSelect(int row);
+
+protected:
+ void Busy(void);
+ void DATA(char data,char type);
+ DigitalOut _RS, _E;
+ BusOut _DBUS;
+};
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Dec 12 17:05:59 2017 +0000
@@ -0,0 +1,100 @@
+#include "mbed.h"
+#include "main.h"
+
+
+
+
+LCD lcd(PD_15, PF_12, PF_13, PE_9, PF_14, PF_15);
+
+BMP280 Sensor(D14, D15);
+void PrintLCD ();
+
+
+
+float LDR_Value;
+float temp_Value;
+float press_Value;
+Thread t1;
+Thread t2;
+
+Mutex door;
+
+void PrintLCD () {
+
+ int i = 0;
+ while(1){
+ char DataString[16];
+ lcd.Clear();
+ lcd.RowSelect(0);
+
+ switch (i){
+ case 0:
+
+
+ sprintf(DataString,"%.4f", LDR_Value);
+ lcd.Write("Light Level:");
+ i++;
+ break;
+ case 1:
+
+
+ sprintf(DataString,"%2.2f", temp_Value);
+ lcd.Write("Temperature:");
+ i++;
+
+ break;
+
+ case 2:
+
+ sprintf(DataString,"%4.2f", press_Value);
+ lcd.Write("Pressure:");
+ i =0;
+ break;
+ default:
+ i = 0;
+ break;
+ }
+
+ lcd.RowSelect(1);
+ lcd.Write(DataString);
+ Thread::wait (5000);
+ }
+}
+
+
+int main() {
+
+ t1.start(PrintLCD);
+
+ while(1) {
+ Green_int = 1;
+
+
+ door.lock();
+
+ LDR_Value = LDR_In.read();
+ temp_Value = Sensor.getTemperature();
+ press_Value = Sensor.getPressure();
+ door.unlock();
+
+
+ Thread::wait (15000);
+ }
+
+}
+
+/*int main(void){
+
+ float temp = 0;
+ //float pressure = 0;
+ char tempString[16];
+ Sensor->initialize();
+ temp = Sensor->getTemperature();
+ lcd->Clear();
+ lcd->RowSelect(0);
+ lcd->Write("Temperature:");
+ sprintf(tempString,"%f",temp);
+ lcd->RowSelect(1);
+ lcd->Write(tempString);
+
+ }*/
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Tue Dec 12 17:05:59 2017 +0000 @@ -0,0 +1,30 @@ +#include "LCD.h" +#include "BMP280.h" + +extern LCD lcd; +extern BMP280 sensor; + + +#define ON 1 +#define OFF 0 + +/* External LEDs as Open Drain */ +DigitalOut Red_ext (PE_15); +DigitalOut Yellow_ext (PB_10); +DigitalOut Green_ext (PB_11); + +/* Configure On-board LEDS */ +DigitalOut Green_int (LED1); +DigitalOut Blue_int (LED2); +DigitalOut Red_int (LED3); + +/* Configure Digital In Switches */ +DigitalIn SW_L (PE_12); +DigitalIn SW_R (PE_14); + +/* Configure Analogue Pins */ +/* Analogue IN */ +AnalogIn LDR_In (PA_0); + +/* Congfigure Serial interface */ +Serial pc(USBTX, USBRX); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Tue Dec 12 17:05:59 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#5f6572179d66ce4c09d6517b659ac51133cc980d
