Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #define SYS_CLOCK_HZ 16000000
- #define BAUD 9600
- byte* sendBits= (byte*)malloc(8);
- byte* buff=(char*) malloc(200);
- int pos,sendPos;
- char ch;
- void setup()
- {
- DDRA=0xFE;
- PORTA=0x04;
- Serial.begin(9600);
- }
- void writeSerial(byte* data,int cnt)
- {
- //Set TX bit to low to start trasmission
- for(int i=0;i<cnt;i++)
- {
- for(int p=0;p<8;p++)
- {
- sendBits[p]=( ( data[i] & (1 << p) ) >>p );
- switch(sendBits[p])
- {
- case 1:
- Serial.write("1");
- break;
- case 0:
- Serial.write("0");
- break;
- }
- }
- sendPos=0;
- PORTA &= ~(0x04);
- while(sendPos<8)
- {
- delayMicroseconds(1000000/BAUD);
- PORTA=sendBits[sendPos++] << 2;
- }
- delayMicroseconds(1000000/BAUD);
- PORTA |= 0x04;
- }
- }
- void loop()
- {
- pos=0;
- while(Serial.available())
- {
- ch=Serial.read();
- if(ch!=13 && ch!=10)
- buff[pos++]=ch;
- }
- writeSerial(buff,pos);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement