![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
aa
Diff: main.cpp
- Revision:
- 1:fe3f80c4beeb
- Parent:
- 0:0311bb0b38f7
- Child:
- 2:3459b9282009
--- a/main.cpp Mon Sep 09 00:16:13 2019 +0000 +++ b/main.cpp Wed Sep 18 00:22:34 2019 +0000 @@ -58,6 +58,7 @@ I2C i2c(SDA,SCL); SO1602A oled(i2c,0x78); + //********** pin select **********// //********** define **********// @@ -69,14 +70,15 @@ #define SENSORDATA_SIZE 48 const int pinDef[48] = { 0, 1, 2, 3, 4, 5, - 12,13,14,15, 7, 6, - 22,23, 8, 9,10,11, - 16,17,18,19,20,21, - 27,26,25,24,40,41, - 28,29,30,31,38,39, - 32,33,34,35,36,37, - 42,43,44,45,36,47}; - + 12,13,14,15, 7, 6, + 22,23, 8, 9,10,11, + 16,17,18,19,20,21, + 27,26,25,24,40,41, + 28,29,30,31,38,39, + 32,33,34,35,36,37, + 42,43,44,45,36,47 + }; + const int weight[6] = { 2, 1, 0, 0,-1,-2}; char send[SENDDATA_SIZE] = {60,77,80,55,65,68,90,87}; @@ -89,35 +91,51 @@ void SendDataMake(bool sensorData[], char sendData[]); //********** define **********// -void InitiaLize(void) +void InitiaLize(void) { uartSE = 1; //送信固定 - + uart.baud(9600); uart.attach(Transmit,Serial::TxIrq); } -int main(void) +int main(void) { InitiaLize(); - - while(1) - { + oled.init(); + oled.setDispFlag(true,false,false); + while(1) { + if(send[2]>250) { + oled.locate(0,0); + oled.printf("%d",send[2]-256); + } else { + oled.locate(0,0); + oled.printf("%2d",send[2]); + } + if(send[3]>250) { + oled.locate(5,0); + oled.printf("%d",send[3]-256); + } else { + oled.locate(5,0); + oled.printf("%2d",send[3]); + } LineDataRead(line,SENSORDATA_SIZE); SendDataMake(line,send); SendDataUpdate(send,SENDDATA_SIZE); } } -void Transmit() { +void Transmit() +{ __disable_irq(); //uart.printf("%d\n\r",RS485uart.GetData()); uart.putc(RS485uart.GetData()); __enable_irq(); - + } -void SendDataUpdate(char sendData[], int dataSize) { +void SendDataUpdate(char sendData[], int dataSize) +{ __disable_irq(); if(!RS485uart.InAnyData()) { RS485uart.PutData('S'); @@ -126,10 +144,11 @@ } RS485uart.PutData('F'); } - __enable_irq(); + __enable_irq(); } -void PinSelect(int pin) { +void PinSelect(int pin) +{ bool selectnum[16][4]= { {0,0,0,0}, {0,0,0,1}, @@ -178,9 +197,10 @@ } } -void LineDataRead(bool sensorData[], int dataSize) { +void LineDataRead(bool sensorData[], int dataSize) +{ int pin; - int readData = 0; + int readData = 0; for(int i = 0; i < dataSize; i++) { pin = pinDef[i]; PinSelect(pin); @@ -196,11 +216,12 @@ } else { sensorData[i] = 1; } - + } } -void SendDataMake(bool sensorData[], char sendData[]) { +void SendDataMake(bool sensorData[], char sendData[]) +{ int data = 0; bool ACflag = true; bool NCflag = true; @@ -215,8 +236,8 @@ else if(sensorData[count] == 0) NCflag = false; count++; } - if(NCflag) sendData[i] = 'N'; - else if(ACflag) sendData[i] = 'A'; + if(NCflag) sendData[i] = 99; + else if(ACflag) sendData[i] = 98; else sendData[i] = data; } } \ No newline at end of file