df

Dependencies:   mbed

Fork of APP1 by Team APP

Committer:
GaiSensei
Date:
Mon Jan 16 00:06:45 2017 +0000
Revision:
13:bb9669053eb3
Parent:
10:04822743cefe
Child:
14:2f89279586cb
Create homemade_mbed functions; ; - Read bits; - Write bits; ; Sorry messy commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GaiSensei 2:b8a20f7e2912 1 #include "UARTDisplayer.hpp"
GaiSensei 13:bb9669053eb3 2 #include <cstdio>
GaiSensei 13:bb9669053eb3 3 #include "Utility.hpp"
GaiSensei 13:bb9669053eb3 4 #include "mbed.h" //Needed for function wait
GaiSensei 2:b8a20f7e2912 5
GaiSensei 13:bb9669053eb3 6 UARTDisplayer::UARTDisplayer(PinName tx_pin) :
GaiSensei 13:bb9669053eb3 7 device(tx_pin)
GaiSensei 2:b8a20f7e2912 8 {
GaiSensei 2:b8a20f7e2912 9
GaiSensei 2:b8a20f7e2912 10 }
GaiSensei 2:b8a20f7e2912 11
GaiSensei 2:b8a20f7e2912 12 void UARTDisplayer::displayAngle(float angle)
GaiSensei 2:b8a20f7e2912 13 {
GaiSensei 13:bb9669053eb3 14 char digits[6];
GaiSensei 13:bb9669053eb3 15 std::snprintf(digits, sizeof digits, "%f", angle);
GaiSensei 2:b8a20f7e2912 16
GaiSensei 2:b8a20f7e2912 17 if(digits[1] == '.')
GaiSensei 2:b8a20f7e2912 18 {
GaiSensei 2:b8a20f7e2912 19 device.write(0);
GaiSensei 2:b8a20f7e2912 20 wait(0.001);
GaiSensei 2:b8a20f7e2912 21 device.write((int)digits[0] - 48);
GaiSensei 2:b8a20f7e2912 22 wait(0.001);
GaiSensei 2:b8a20f7e2912 23 device.write((int)digits[2] - 48);
GaiSensei 2:b8a20f7e2912 24 wait(0.001);
GaiSensei 2:b8a20f7e2912 25 device.write((int)digits[3] - 48);
GaiSensei 2:b8a20f7e2912 26 wait(0.001);
GaiSensei 2:b8a20f7e2912 27 }
GaiSensei 2:b8a20f7e2912 28 else
GaiSensei 2:b8a20f7e2912 29 {
GaiSensei 2:b8a20f7e2912 30 device.write((int)digits[0] - 48);
GaiSensei 2:b8a20f7e2912 31 wait(0.001);
GaiSensei 2:b8a20f7e2912 32 device.write((int)digits[1] - 48);
GaiSensei 2:b8a20f7e2912 33 wait(0.001);
GaiSensei 2:b8a20f7e2912 34 device.write((int)digits[3] - 48);
GaiSensei 2:b8a20f7e2912 35 wait(0.001);
GaiSensei 2:b8a20f7e2912 36 device.write((int)digits[4] - 48);
GaiSensei 2:b8a20f7e2912 37 wait(0.001);
GaiSensei 2:b8a20f7e2912 38 }
GaiSensei 2:b8a20f7e2912 39
GaiSensei 2:b8a20f7e2912 40 device.write(DECIMAL_CONTROL_REGISTER);
GaiSensei 2:b8a20f7e2912 41 wait(0.001);
GaiSensei 2:b8a20f7e2912 42 device.write(FLOATING_POINT_DOT_POSITION);
GaiSensei 2:b8a20f7e2912 43 wait(0.001);
GaiSensei 2:b8a20f7e2912 44 }
GaiSensei 2:b8a20f7e2912 45
GaiSensei 2:b8a20f7e2912 46 void UARTDisplayer::reset()
GaiSensei 2:b8a20f7e2912 47 {
GaiSensei 13:bb9669053eb3 48 device.write(CLEAR_DISPLAY_REGISTER);
GaiSensei 2:b8a20f7e2912 49 wait(0.001);
GaiSensei 2:b8a20f7e2912 50 device.write(CURSOR_CONROL_REGISTER);
GaiSensei 2:b8a20f7e2912 51 wait(0.001);
GaiSensei 2:b8a20f7e2912 52 device.write(MOST_LEFT_DIGIT_POSITION);
GaiSensei 2:b8a20f7e2912 53 wait(0.001);
GaiSensei 13:bb9669053eb3 54 }
GaiSensei 13:bb9669053eb3 55
GaiSensei 13:bb9669053eb3 56 HomemadeUART::HomemadeUART(PinName tx_pin) :
GaiSensei 13:bb9669053eb3 57 tx_pin(tx_pin)
GaiSensei 13:bb9669053eb3 58 {
GaiSensei 13:bb9669053eb3 59 }
GaiSensei 13:bb9669053eb3 60
GaiSensei 13:bb9669053eb3 61 void HomemadeUART::write(const int value)
GaiSensei 13:bb9669053eb3 62 {
GaiSensei 13:bb9669053eb3 63 //TODO
GaiSensei 13:bb9669053eb3 64 }
GaiSensei 13:bb9669053eb3 65
GaiSensei 13:bb9669053eb3 66 void HomemadeUART::init()
GaiSensei 13:bb9669053eb3 67 {
GaiSensei 13:bb9669053eb3 68 int* register_address1 = reinterpret_cast<int*>(0x400FC0C4);
GaiSensei 13:bb9669053eb3 69 const int previous_register_value1 = *register_address1;
GaiSensei 13:bb9669053eb3 70 int new_register_value1 = previous_register_value1;
GaiSensei 13:bb9669053eb3 71 new_register_value1 = utility::update_bit(new_register_value1, 22, 1);
GaiSensei 13:bb9669053eb3 72 new_register_value1 = utility::update_bit(new_register_value1, 23, 1);
GaiSensei 13:bb9669053eb3 73 *register_address1 = new_register_value1;
GaiSensei 2:b8a20f7e2912 74
GaiSensei 13:bb9669053eb3 75 int* register_address2 = reinterpret_cast<int*>(0x4000C00C);
GaiSensei 13:bb9669053eb3 76 const int previous_register_value2 = *register_address2;
GaiSensei 13:bb9669053eb3 77 int new_register_value2 = previous_register_value2;
GaiSensei 13:bb9669053eb3 78 new_register_value2 = utility::update_bit(new_register_value2, 7, 1);
GaiSensei 13:bb9669053eb3 79 *register_address2 = new_register_value2;
GaiSensei 13:bb9669053eb3 80
GaiSensei 13:bb9669053eb3 81 int* register_address3 = reinterpret_cast<int*>(0x4009800C);
GaiSensei 13:bb9669053eb3 82 const int previous_register_value3 = *register_address3;
GaiSensei 13:bb9669053eb3 83 int new_register_value3 = previous_register_value3;
GaiSensei 13:bb9669053eb3 84 new_register_value3 = utility::update_bit(new_register_value3, 7, 1);
GaiSensei 13:bb9669053eb3 85 *register_address3 = new_register_value3;
GaiSensei 13:bb9669053eb3 86
GaiSensei 13:bb9669053eb3 87 int* register_address4 = reinterpret_cast<int*>(0x4009C00C);
GaiSensei 13:bb9669053eb3 88 const int previous_register_value4 = *register_address4;
GaiSensei 13:bb9669053eb3 89 int new_register_value4 = previous_register_value4;
GaiSensei 13:bb9669053eb3 90 new_register_value4 = utility::update_bit(new_register_value4, 7, 1);
GaiSensei 13:bb9669053eb3 91 *register_address4 = new_register_value4;
GaiSensei 2:b8a20f7e2912 92 }