Bruno Allaire-Lemay
/
APP1test
df
Fork of APP1 by
SPIDisplayer.cpp@23:2531e72d92b9, 2017-02-09 (annotated)
- Committer:
- GaiSensei
- Date:
- Thu Feb 09 15:55:18 2017 +0000
- Revision:
- 23:2531e72d92b9
- Parent:
- 21:a111be2582be
gh
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dupm2216 | 21:a111be2582be | 1 | ///////////////////////////////////////////////////////////// |
dupm2216 | 21:a111be2582be | 2 | // APP 1: Systèmes à microprocesseurs // |
dupm2216 | 21:a111be2582be | 3 | // // |
dupm2216 | 21:a111be2582be | 4 | // Université de Sherbrooke // |
dupm2216 | 21:a111be2582be | 5 | // Génie informatique // |
dupm2216 | 21:a111be2582be | 6 | // Session 5, Hiver 2017 // |
dupm2216 | 21:a111be2582be | 7 | // // |
dupm2216 | 21:a111be2582be | 8 | // Date: 17 janvier 2017 // |
dupm2216 | 21:a111be2582be | 9 | // // |
dupm2216 | 21:a111be2582be | 10 | // Auteurs: Maxime Dupuis, dupm2216 // |
dupm2216 | 21:a111be2582be | 11 | // Bruno Allaire-Lemay, allb2701 // |
dupm2216 | 21:a111be2582be | 12 | ///////////////////////////////////////////////////////////// |
dupm2216 | 21:a111be2582be | 13 | |
GaiSensei | 2:b8a20f7e2912 | 14 | #include "SPIDisplayer.hpp" |
GaiSensei | 2:b8a20f7e2912 | 15 | |
GaiSensei | 2:b8a20f7e2912 | 16 | SPIDisplayer::SPIDisplayer(PinName mosi, PinName miso, PinName sclk, PinName ssel): |
GaiSensei | 2:b8a20f7e2912 | 17 | device(SPI(mosi, miso, sclk, ssel)), |
GaiSensei | 2:b8a20f7e2912 | 18 | pc(Serial(USBTX, USBRX)) |
GaiSensei | 2:b8a20f7e2912 | 19 | { |
GaiSensei | 2:b8a20f7e2912 | 20 | |
GaiSensei | 2:b8a20f7e2912 | 21 | } |
GaiSensei | 2:b8a20f7e2912 | 22 | |
GaiSensei | 2:b8a20f7e2912 | 23 | void SPIDisplayer::displayAngle(float angle) |
GaiSensei | 2:b8a20f7e2912 | 24 | { |
GaiSensei | 2:b8a20f7e2912 | 25 | char digits[6]; |
GaiSensei | 2:b8a20f7e2912 | 26 | snprintf(digits, sizeof digits, "%f", angle); |
GaiSensei | 2:b8a20f7e2912 | 27 | |
GaiSensei | 2:b8a20f7e2912 | 28 | if(digits[1] == '.') |
GaiSensei | 2:b8a20f7e2912 | 29 | { |
GaiSensei | 2:b8a20f7e2912 | 30 | device.write(0); |
GaiSensei | 2:b8a20f7e2912 | 31 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 32 | device.write((int)digits[0] - 48); |
GaiSensei | 2:b8a20f7e2912 | 33 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 34 | device.write((int)digits[2] - 48); |
GaiSensei | 2:b8a20f7e2912 | 35 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 36 | device.write((int)digits[3] - 48); |
GaiSensei | 2:b8a20f7e2912 | 37 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 38 | } |
GaiSensei | 2:b8a20f7e2912 | 39 | else |
GaiSensei | 2:b8a20f7e2912 | 40 | { |
GaiSensei | 2:b8a20f7e2912 | 41 | device.write((int)digits[0] - 48); |
GaiSensei | 2:b8a20f7e2912 | 42 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 43 | device.write((int)digits[1] - 48); |
GaiSensei | 2:b8a20f7e2912 | 44 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 45 | device.write((int)digits[3] - 48); |
GaiSensei | 2:b8a20f7e2912 | 46 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 47 | device.write((int)digits[4] - 48); |
GaiSensei | 2:b8a20f7e2912 | 48 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 49 | } |
GaiSensei | 2:b8a20f7e2912 | 50 | |
GaiSensei | 2:b8a20f7e2912 | 51 | device.write(DECIMAL_CONTROL_REGISTER); |
GaiSensei | 2:b8a20f7e2912 | 52 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 53 | device.write(FLOATING_POINT_DOT_POSITION); |
GaiSensei | 2:b8a20f7e2912 | 54 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 55 | } |
GaiSensei | 2:b8a20f7e2912 | 56 | |
GaiSensei | 2:b8a20f7e2912 | 57 | void SPIDisplayer::reset() |
GaiSensei | 2:b8a20f7e2912 | 58 | { |
GaiSensei | 2:b8a20f7e2912 | 59 | device.write(CLEAR_DISPLAY_REGISTER); |
GaiSensei | 2:b8a20f7e2912 | 60 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 61 | device.write(CURSOR_CONROL_REGISTER); |
GaiSensei | 2:b8a20f7e2912 | 62 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 63 | device.write(MOST_LEFT_DIGIT_POSITION); |
GaiSensei | 2:b8a20f7e2912 | 64 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 65 | } |