Bruno Allaire-Lemay
/
APP1test
df
Fork of APP1 by
UARTDisplayer.cpp
- Committer:
- GaiSensei
- Date:
- 2017-01-16
- Revision:
- 13:bb9669053eb3
- Parent:
- 10:04822743cefe
- Child:
- 14:2f89279586cb
File content as of revision 13:bb9669053eb3:
#include "UARTDisplayer.hpp" #include <cstdio> #include "Utility.hpp" #include "mbed.h" //Needed for function wait UARTDisplayer::UARTDisplayer(PinName tx_pin) : device(tx_pin) { } void UARTDisplayer::displayAngle(float angle) { char digits[6]; std::snprintf(digits, sizeof digits, "%f", angle); if(digits[1] == '.') { device.write(0); wait(0.001); device.write((int)digits[0] - 48); wait(0.001); device.write((int)digits[2] - 48); wait(0.001); device.write((int)digits[3] - 48); wait(0.001); } else { device.write((int)digits[0] - 48); wait(0.001); device.write((int)digits[1] - 48); wait(0.001); device.write((int)digits[3] - 48); wait(0.001); device.write((int)digits[4] - 48); wait(0.001); } device.write(DECIMAL_CONTROL_REGISTER); wait(0.001); device.write(FLOATING_POINT_DOT_POSITION); wait(0.001); } void UARTDisplayer::reset() { device.write(CLEAR_DISPLAY_REGISTER); wait(0.001); device.write(CURSOR_CONROL_REGISTER); wait(0.001); device.write(MOST_LEFT_DIGIT_POSITION); wait(0.001); } HomemadeUART::HomemadeUART(PinName tx_pin) : tx_pin(tx_pin) { } void HomemadeUART::write(const int value) { //TODO } void HomemadeUART::init() { int* register_address1 = reinterpret_cast<int*>(0x400FC0C4); const int previous_register_value1 = *register_address1; int new_register_value1 = previous_register_value1; new_register_value1 = utility::update_bit(new_register_value1, 22, 1); new_register_value1 = utility::update_bit(new_register_value1, 23, 1); *register_address1 = new_register_value1; int* register_address2 = reinterpret_cast<int*>(0x4000C00C); const int previous_register_value2 = *register_address2; int new_register_value2 = previous_register_value2; new_register_value2 = utility::update_bit(new_register_value2, 7, 1); *register_address2 = new_register_value2; int* register_address3 = reinterpret_cast<int*>(0x4009800C); const int previous_register_value3 = *register_address3; int new_register_value3 = previous_register_value3; new_register_value3 = utility::update_bit(new_register_value3, 7, 1); *register_address3 = new_register_value3; int* register_address4 = reinterpret_cast<int*>(0x4009C00C); const int previous_register_value4 = *register_address4; int new_register_value4 = previous_register_value4; new_register_value4 = utility::update_bit(new_register_value4, 7, 1); *register_address4 = new_register_value4; }