Last active
July 13, 2016 10:24
-
-
Save peanutwolf/0c8e7ea9773c67f2918c to your computer and use it in GitHub Desktop.
Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#include </home/peanutwolf/Документы/myKIPP/RingBuffer.h> | |
#define USART_BAUDRATE 9600 | |
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1) | |
volatile char *sramAdress; | |
volatile uint8_t temp_pointer; | |
bool flag = true; | |
void writeSram(char data){ | |
*sramAdress = data; | |
sramAdress++; | |
} | |
void send_USART(){ | |
temp_pointer = buf_pointer; | |
UCSRB |=_BV(UDRIE); | |
} | |
int main (void) | |
{ | |
UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception circuitry | |
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes | |
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register | |
UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register | |
UCSRB |= (1 << RXCIE); // Enable the USART Recieve Complete interrupt (USART_RXC) | |
sramAdress= 0x66; | |
sei(); // Enable the Global Interrupt Enable flag so that interrupts can be processed | |
DDRC = 0b00000011; | |
for (;;) // Loop forever | |
{ | |
PORTC = 0x01; // Do nothing - echoing is handled by the ISR instead of in the main loop | |
if((buf_pointer>=5)&flag){ | |
flag=false; | |
send_USART(); | |
} | |
} | |
} | |
ISR (USART_UDRE_vect){ | |
if(!buf_isEmpty()){ | |
// UDR = RING_BUFFER[temp_pointer]; | |
UDR = 0x40; | |
temp_pointer++; | |
buf_pointer--; | |
} | |
else{ | |
UCSRB &=~_BV(UDRIE); | |
} | |
} | |
ISR(USART_RXC_vect) | |
{ | |
char ReceivedByte; | |
ReceivedByte = UDR; // Fetch the received byte value into the variable "ByteReceived" | |
buf_push_char(ReceivedByte); | |
//UDR = 0x40; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include </home/peanutwolf/Документы/myKIPP/RingBuffer.h> | |
void buf_push_char(char data){ | |
if(buf_pointer<=90){ | |
RING_BUFFER[buf_pointer] = data; | |
buf_pointer++; | |
} | |
else{ | |
return; | |
} | |
} | |
char buf_pop_char(){ | |
char data; | |
if(!buf_isEmpty()){ | |
data=RING_BUFFER[buf_pointer]; | |
buf_pointer--; | |
return data; | |
} | |
else{ | |
return 0; | |
} | |
} | |
bool buf_isEmpty(){ | |
if(buf_pointer==0){ | |
return true; | |
} | |
else{ | |
return false; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef RINGBUFFER_H_INCLUDED | |
#define RINGBUFFER_H_INCLUDED | |
#include <stdbool.h> | |
#include <stdint.h> | |
#define BUF_SIZE 100 | |
volatile char RING_BUFFER[BUF_SIZE]; | |
volatile uint8_t buf_pointer; | |
void buf_push_char(char data); | |
char buf_pop_char(); | |
bool buf_isEmpty(); | |
#endif // RINGBUFFER_H_INCLUDED |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment