Initial commit
This commit is contained in:
41
code/src/DS3231.c
Normal file
41
code/src/DS3231.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include "i2c.h"
|
||||
#include "DS3231.h"
|
||||
#include "pinout.h"
|
||||
#include <avr/io.h>
|
||||
|
||||
|
||||
|
||||
void DS3231_init(void){
|
||||
//i2c_start(DS3231_ADDRESS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int DS3231_seconds(void){
|
||||
|
||||
char ret = i2c_start(DS3231_ADDRESS+I2C_WRITE);
|
||||
/*
|
||||
USART_Transmit_String(" Return ");
|
||||
//putchar(ret);
|
||||
USART_Transmit_String("\n");
|
||||
*/
|
||||
/*
|
||||
if(ret){ //failed
|
||||
PORTB |= STATUS_LED_B;
|
||||
i2c_stop();
|
||||
}else{
|
||||
// issuing start condition ok, device accessible
|
||||
i2c_write(0x05); // write address = 5
|
||||
i2c_write(0x75); // ret=0 -> Ok, ret=1 -> no ACK
|
||||
i2c_stop();
|
||||
|
||||
i2c_start_wait(DS3231_ADDRESS+I2C_WRITE); // set device address and write mode
|
||||
i2c_write(REG_SECONDS); // write address = 5
|
||||
i2c_rep_start(DS3231_ADDRESS+I2C_READ); // set device address and read mode
|
||||
ret = i2c_readNak(); // read one byte
|
||||
i2c_stop();
|
||||
}
|
||||
|
||||
return ret;
|
||||
*/
|
||||
}
|
||||
25
code/src/adc.c
Normal file
25
code/src/adc.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "adc.h"
|
||||
#include "pinout.h"
|
||||
#include <avr/io.h>
|
||||
|
||||
void adc_setup(void){
|
||||
ADMUX = (1 << REFS0); //Versorgungsspannung definieren
|
||||
ADCSRA|= (1 << ADEN) //enable bit für adc
|
||||
| (1 << ADPS0) //setze Prescaler für Abtastfrequenz
|
||||
| (1 << ADPS1) //setze Prescaler für Abtastfrequenz
|
||||
| (0 << ADPS2); //setze Prescaler für Abtastfrequenz
|
||||
}
|
||||
|
||||
|
||||
|
||||
int adc_read(unsigned char adc_pin) {
|
||||
ADMUX &= 0b11110000; //Alte Port-Select Flags löschen
|
||||
ADMUX|=adc_pin; //Neuen Eingang setzen
|
||||
ADCSRA |= (1 << ADSC); // eine Wandlung "single conversion"
|
||||
while (ADCSRA & (1 << ADSC) ) { // auf Abschluss der Konvertierung warten
|
||||
}
|
||||
int ADCresult = ADCL;
|
||||
ADCresult += (ADCH << 8);
|
||||
return ADCresult;
|
||||
}
|
||||
|
||||
94
code/src/i2c.c
Normal file
94
code/src/i2c.c
Normal file
@@ -0,0 +1,94 @@
|
||||
#include "i2c.h"
|
||||
#include "pinout.h"
|
||||
#include <util/twi.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
|
||||
void i2c_init(void)
|
||||
{
|
||||
/* initialize TWI clock: 100 kHz clock, TWPS = 0 => prescaler = 1 */
|
||||
|
||||
TWSR = 1; /* no prescaler */
|
||||
TWBR = ((F_CPU/SCL_CLOCK)-16)/2; /* must be > 10 for stable operation */
|
||||
|
||||
}
|
||||
|
||||
|
||||
unsigned char i2c_start(unsigned char address){
|
||||
char DATA = 0b10011000;
|
||||
//Send START condition
|
||||
TWCR = (1<<TWINT)|
|
||||
(1<<TWSTA)|
|
||||
(1<<TWEN);
|
||||
|
||||
//Wait for TWINT Flag set. This indicates that the START condition has been transmitted.
|
||||
while (!(TWCR &(1<<TWINT)));
|
||||
|
||||
//Check value of TWI Status Register. Mask prescaler bits. If status different from START go to ERROR.
|
||||
if ((TWSR & 0xF8) != TW_START){
|
||||
//ERROR();
|
||||
}
|
||||
|
||||
//Load SLA_W into TWDR Register. Clear TWINT bit in TWCR to start transmission of address.
|
||||
TWDR = address + I2C_WRITE;
|
||||
TWCR = (1<<TWINT) |
|
||||
(1<<TWEN);
|
||||
|
||||
//Wait for TWINT Flag set. This indicates that the SLA+W has been transmitted, and ACK/NACK has been received.
|
||||
while (!(TWCR & (1<<TWINT)));
|
||||
|
||||
//Check value of TWI Status Register. Mask prescaler bits. If status different from MT_SLA_ACK go to ERROR.
|
||||
if ((TWSR & 0xF8) != TW_MT_SLA_ACK){
|
||||
// ERROR();
|
||||
}
|
||||
|
||||
//Load DATA into TWDR Register. Clear TWINT bit in TWCR to start transmission of data.
|
||||
TWDR = DATA;
|
||||
TWCR = (1<<TWINT) |
|
||||
(1<<TWEN);
|
||||
|
||||
//Wait for TWINT Flag set. This indicates that the DATA has been transmitted, and ACK/NACK has been received.
|
||||
while (!(TWCR &(1<<TWINT)));
|
||||
|
||||
//Check value of TWI Status Register. Mask prescaler bits. If status different from MT_DATA_ACK go to ERROR.
|
||||
if ((TWSR & 0xF8) != TW_MT_DATA_ACK){
|
||||
// ERROR();
|
||||
}
|
||||
|
||||
//Transmit STOP condition
|
||||
TWCR = (1<<TWINT)|
|
||||
(1<<TWEN) |
|
||||
(1<<TWSTO);
|
||||
|
||||
|
||||
/*
|
||||
TWCR = _BV(TWINT) | _BV(TWSTA) | _BV(TWEN);
|
||||
while (!(TWCR & (1<<TWINT)));
|
||||
if ((TWSR & 0xF8) != TW_START)
|
||||
return 1;
|
||||
//ERROR(); //Fehlerbehandlung
|
||||
TWDR = address + I2C_WRITE;
|
||||
TWCR = (1<<TWINT) | (1<<TWEN);
|
||||
while (!(TWCR & (1<<TWINT)));
|
||||
if ((TWSR & 0xF8) != TW_MT_SLA_ACK)
|
||||
//ERROR();
|
||||
return 2;
|
||||
|
||||
TWDR = address;
|
||||
TWCR = (1<<TWINT) | (1<<TWEN);
|
||||
while (!(TWCR & (1<<TWINT)));
|
||||
if ((TWSR & 0xF8) != TW_MT_DATA_ACK)
|
||||
return 3;
|
||||
//ERROR();
|
||||
TWCR = (1<<TWINT)|(1<<TWEN)|
|
||||
(1<<TWSTO);
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
301
code/src/main.c
Normal file
301
code/src/main.c
Normal file
@@ -0,0 +1,301 @@
|
||||
//#define F_CPU 16000000L
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include <avr/interrupt.h> //interrupts
|
||||
#include <stdlib.h>
|
||||
#include "pinout.h"
|
||||
#include "print.h"
|
||||
#include "adc.h"
|
||||
#include "uart.h"
|
||||
#include "i2c.h"
|
||||
#include "DS3231.h"
|
||||
|
||||
|
||||
/*README
|
||||
DIP1 aktiviert Röhren-Schaltregler
|
||||
*/
|
||||
|
||||
volatile int counter = 0;
|
||||
char text[22] = {'F','R','o','h','e',' ',' ','W','e','i','h','n','a','c','h','t','e', 'n', ' ',' ', ' ', ' '};
|
||||
//char text[18] = {'1','2','3','4','5','6','7','8','9','t','s','c','a','f','e',' ', ' ', ' '};
|
||||
int offset = 0;
|
||||
int animationtimer = 0;
|
||||
int stringlength = 22;
|
||||
int duty = 125;
|
||||
|
||||
|
||||
void check_dip_switches(void);
|
||||
void check_buttons(void);
|
||||
void setup(void);
|
||||
void set_PWM_duty(int dutycycle);
|
||||
|
||||
int main(void){
|
||||
setup();
|
||||
|
||||
while(1){
|
||||
//putchar('c');
|
||||
//_delay_ms(50);
|
||||
|
||||
check_dip_switches();
|
||||
check_buttons();
|
||||
|
||||
|
||||
|
||||
char current_section[6];
|
||||
for(int i = 0; i < 6; i++){
|
||||
current_section[i] = text[(i+offset)%stringlength];
|
||||
if(text[(i+offset)%stringlength] == ' ' && text[(i+1+offset)%stringlength] == ' '){
|
||||
PORTC |= DOT;
|
||||
}else{
|
||||
PORTC &= ~DOT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//for(int i = 0; i < 6; i++){}
|
||||
//char test_word[6] = {'0','0','0','0','0', (char)i};
|
||||
print_String(current_section);
|
||||
//i2c_start(0b00101010);
|
||||
// current_e
|
||||
|
||||
|
||||
|
||||
/*
|
||||
for(int i = 0; i < 6; i++)
|
||||
SR_Buffer[i] = i;
|
||||
|
||||
print_SR_Buffer();
|
||||
*/
|
||||
//putchar((i2c_start(0x68))+48);
|
||||
//i2c_write(0b00101010);
|
||||
}
|
||||
}
|
||||
|
||||
void check_dip_switches() {
|
||||
if (PINB & DIP_1) {
|
||||
PORTC |= ENABLE_TUBE_PSU;
|
||||
PORTA &= ~ENABLE_TUBE_SUPPLY;
|
||||
// PORTB |= STATUS_LED_B;
|
||||
} else {
|
||||
PORTC &= ~(ENABLE_TUBE_PSU);
|
||||
PORTA |= (ENABLE_TUBE_SUPPLY);
|
||||
// PORTB &= ~STATUS_LED_B;
|
||||
}
|
||||
}
|
||||
|
||||
void check_buttons(){
|
||||
if((PINC & BUTTON_A)){
|
||||
// PORTB &= ~STATUS_LED_C;
|
||||
}
|
||||
};
|
||||
|
||||
void setup(){
|
||||
|
||||
DDRA = ENABLE_TUBE_SUPPLY;
|
||||
|
||||
DDRB = STATUS_LED_B
|
||||
| STATUS_LED_C
|
||||
| MOSI
|
||||
| CLK;
|
||||
|
||||
DDRC = LATCH_SR
|
||||
| ENABLE_SR
|
||||
| DOT
|
||||
| ENABLE_TUBE_PSU;
|
||||
|
||||
DDRD = RESET_SR
|
||||
| TUBE_LED;
|
||||
|
||||
|
||||
//--------------------------
|
||||
// SPI
|
||||
//--------------------------
|
||||
SPCR = (1 << SPE) | //enable SPI
|
||||
(1 << MSTR) | //SPI als Master starten
|
||||
(1 << SPR0) | //clock-prescaler LSB
|
||||
(1 << SPR1) | //clock-prescaler MSB
|
||||
(0 << SPIE) | //complete transfer/ recive interrupt
|
||||
(0 << CPOL) |
|
||||
(0 << CPHA) |
|
||||
(0 << DORD); //MSB first = 0
|
||||
SPSR = (1 << SPI2X);// | //clock- prescaler double speed
|
||||
|
||||
PORTC &= ~LATCH_SR; //latch low, sonst startet SPI nicht
|
||||
PORTC |= LATCH_SR;
|
||||
PORTD |= RESET_SR; //Setzte Reset auf HIGH (active LOW)
|
||||
PORTC &= ~(ENABLE_SR); //Aktiviert Shiftregister (active LOW)
|
||||
|
||||
|
||||
|
||||
//--------------------------
|
||||
// Externe Interrupts
|
||||
//--------------------------
|
||||
//External Interrupt Mask Register
|
||||
|
||||
EIMSK |= (1 << INT0) | //Aktiviere Interrupt INT0
|
||||
(1 << INT1); //Aktiviere Interrupt INT1
|
||||
|
||||
//External Interrupt Control Register A
|
||||
EICRA |= (0 << ISC10) | //Interrupt bei jedem Pegelwechsel auf INT1
|
||||
(1 << ISC11) |
|
||||
(1 << ISC00) | //Interrupt bei jedem Pegelwechsel auf INT0
|
||||
(1 << ISC01);
|
||||
//Pin Change Interrupt Control Register
|
||||
PCICR |= (1 << PCIE2); //Enabled PCINT16-23 als mögliche Signalquelle für Interrupt
|
||||
|
||||
//Pin Change Mask Register 2
|
||||
//PCMSK2 |= (1 << PCINT18) | //PCINT18 als Signalquelle wählen
|
||||
// (1 << PCINT19); //PCINT19 als Signalquelle wählen
|
||||
|
||||
|
||||
//--------------------------
|
||||
// Timer + Zeitinterrupts
|
||||
//--------------------------
|
||||
|
||||
//PWM-Timer
|
||||
//OC2A set when upcounting, clear when down counting
|
||||
TCCR2A = (1<<COM1A1)
|
||||
| (0<<COM1A0);
|
||||
|
||||
TCCR2B=(1<<WGM20) //Wave form generartion mode
|
||||
|(1<<WGM21) // Wave form generation mode
|
||||
|(1<<COM2A1); //Compare Output Mode
|
||||
|
||||
OCR2A = duty; // Compare value 125
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Timer/Counter control Register A&B
|
||||
//set normal-Mode and waveform
|
||||
TCCR1A = (0 << WGM01) |
|
||||
(0 << WGM00);
|
||||
TCCR1B = (0 << WGM02);
|
||||
|
||||
|
||||
//Prescaler von 1024
|
||||
TCCR1B |= (1 << CS02) |
|
||||
(0 << CS01) |
|
||||
(1 << CS00) ;
|
||||
|
||||
|
||||
//Output compare Regsiter (Setzt Zeit bei der Interrupt auslösen soll)
|
||||
OCR1A = (1 << 7) | //MSB
|
||||
(1 << 6) |
|
||||
(1 << 5) |
|
||||
(1 << 4) |
|
||||
(1 << 3) |
|
||||
(1 << 2) |
|
||||
(1 << 1) |
|
||||
(1 << 0) ; //LSB
|
||||
|
||||
//TIMSK1 |= (1 << OCIE0A); //Interruptvector hinzufügen
|
||||
TIMSK1 |= (1 << ICIE1) | //Interrupt Counter Enabled)
|
||||
(1 << TOIE1); //Timer Overflow Enabled
|
||||
|
||||
|
||||
sei(); //Enable Interrupts
|
||||
//adc_setup();
|
||||
//i2c_init();
|
||||
//USART_Init(MYUBRR);
|
||||
clear_SR_Buffer();
|
||||
|
||||
|
||||
|
||||
}
|
||||
//Timer 1 Interrupt
|
||||
ISR (TIMER1_OVF_vect) // Timer1 ISR
|
||||
{
|
||||
//PORTD ^=TUBE_LED;
|
||||
PORTB ^=STATUS_LED_C;
|
||||
TCNT1 = 63974; //63974; // for 1 sec at 16 MHz
|
||||
animationtimer ++;
|
||||
if(animationtimer > 10){
|
||||
animationtimer= 0;
|
||||
offset++;
|
||||
PORTB ^= STATUS_LED_B;
|
||||
if(offset > 15){
|
||||
offset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Encoder rotate
|
||||
ISR(INT0_vect) {
|
||||
if (PIND & ENCODER_B) {
|
||||
// set_PWM_duty(duty--);
|
||||
} else {
|
||||
// set_PWM_duty(duty++);
|
||||
}
|
||||
}
|
||||
|
||||
//Encoder Button
|
||||
ISR(INT1_vect) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
ISR (USART0_RX_vect){
|
||||
/*
|
||||
//while ( !(UCSR0A & (1<<RXC0)) ){}; //RXC = Recive complete
|
||||
char uart_Buffer[500];
|
||||
char time_string[6];
|
||||
char sat_string[2];
|
||||
sat_string[0]='1';
|
||||
sat_string[1]= '1';
|
||||
|
||||
for(int k = 0; k < 6; k++){
|
||||
time_string[k] = '8';
|
||||
}
|
||||
int i = 0;
|
||||
|
||||
while(UDR0 != '\r' && i < 500){
|
||||
uart_Buffer[i] = UDR0;
|
||||
i++;
|
||||
PORTB ^=STATUS_LED_B;
|
||||
|
||||
|
||||
}
|
||||
|
||||
for(int j = 0; j < 500; j++){
|
||||
|
||||
//if(uart_Buffer[j] == '$'){
|
||||
if(uart_Buffer[j+1] == 'G'){
|
||||
if(uart_Buffer[j+2] == 'P'){
|
||||
if(uart_Buffer[j+3] == 'Z'){
|
||||
if(uart_Buffer[j+4] == 'D'){
|
||||
if(uart_Buffer[j+5] == 'A'){
|
||||
//j++;
|
||||
|
||||
sat_string[0] = uart_Buffer[1];
|
||||
sat_string[1] = uart_Buffer[100];
|
||||
|
||||
//time_string[0] = uart_Buffer[j+36];
|
||||
//time_string[1] = uart_Buffer[j+37];
|
||||
//time_string[2] = uart_Buffer[j+8];
|
||||
//time_string[3] = uart_Buffer[j+9];
|
||||
//time_string[5] = uart_Buffer[j+10];
|
||||
//time_string[6] = uart_Buffer[j+11];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
print_String(sat_string);
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
void set_PWM_duty(int dutycycle){
|
||||
OCR2A = dutycycle;
|
||||
}
|
||||
|
||||
126
code/src/print.c
Normal file
126
code/src/print.c
Normal file
@@ -0,0 +1,126 @@
|
||||
#include "pinout.h"
|
||||
#include "print.h"
|
||||
#include <stdlib.h>
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
const unsigned char number_Font[10] = { 0b11011110, //0
|
||||
0b00000110, //1
|
||||
0b11101010, //2
|
||||
0b01101110, //3
|
||||
0b00110110, //4
|
||||
0b01111100, //5
|
||||
0b11111100, //6
|
||||
0b00001110, //7
|
||||
0b11111110, //8
|
||||
0b01111110 //9
|
||||
};
|
||||
const unsigned char character_Font[26] = {0b10111110, //A
|
||||
0b11110100, //b
|
||||
0b11100000, //c
|
||||
0b11100110, //d
|
||||
0b11111000, //e
|
||||
0b10111000, //F
|
||||
0b11011100, //G
|
||||
0b10110100, //h
|
||||
0b00000100, //i
|
||||
0b01000110, //J
|
||||
0b10111100, //K
|
||||
0b11010000, //L
|
||||
0b10011110, //M
|
||||
0b10100100, //n
|
||||
0b11100100, //o
|
||||
0b10111010, //P
|
||||
0b00111110, //q
|
||||
0b10100000, //r
|
||||
0b01111100, //S
|
||||
0b11110000, //t
|
||||
0b11000100, //u
|
||||
0b11000100, //v
|
||||
0b11010110, //W
|
||||
0b10110110, //X
|
||||
0b01110110, //Y
|
||||
0b11100110 //Z
|
||||
};
|
||||
const unsigned char blank = 0b00000000; //zeigt nichts an
|
||||
const unsigned char minus = 0b00100000; //zeigt '-' an
|
||||
const unsigned char dot = 0b00000001; //aktiviert Dezimalpunkt
|
||||
unsigned char SR_Buffer[6] = {0b11100110,
|
||||
0b11100110,
|
||||
0b11100110,
|
||||
0b11100110,
|
||||
0b11100110,
|
||||
0b11100110,
|
||||
0b11100110,
|
||||
0b11100110};
|
||||
|
||||
|
||||
|
||||
void clear_SR_Buffer() {
|
||||
for (char i = 0; i < 6; i++) {
|
||||
SR_Buffer[i] = blank;
|
||||
}
|
||||
}
|
||||
|
||||
void add_Decimal_Point_to_SR_Buffer(int pos){
|
||||
SR_Buffer[pos-1] += dot;
|
||||
}
|
||||
|
||||
void print_SR_Buffer() {
|
||||
PORTC &= ~(LATCH_SR);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
SPDR = SR_Buffer[i];
|
||||
//SPDR = 0b11100110;
|
||||
//_delay_us(100);
|
||||
while (!(SPSR & (1 << SPIF))); //warten auf transferabschluss
|
||||
}
|
||||
PORTC |= LATCH_SR;
|
||||
//_delay_ms(1);
|
||||
//PORTC &= ~(LATCH_SR);
|
||||
}
|
||||
|
||||
void print_String(char* string){
|
||||
for(int i = 0; i < 6; i++){
|
||||
add_ASCII_to_SR_Buffer(string[i],i);
|
||||
}
|
||||
print_SR_Buffer();
|
||||
}
|
||||
|
||||
|
||||
void add_ASCII_to_SR_Buffer(unsigned char character, int pos) {
|
||||
int ascii_offset = 0;
|
||||
|
||||
if((character > 46) && (character < 57)){ //Char ist Zahl
|
||||
ascii_offset = 48;
|
||||
SR_Buffer[pos] = number_Font[character - ascii_offset]; //Zieht ASCII-Offset ab, sodass Zahl mit Font Index übereinstimmen
|
||||
}else if (character > 95 && character < 122) { //Buchstabe ist kleiner Buchstabe
|
||||
ascii_offset = 97;
|
||||
SR_Buffer[pos] = character_Font[character - ascii_offset]; //Zieht ASCII-Offset ab, sodass Buchstaben mit Font Index übereinstimmen
|
||||
} else if (character > 64 && character < 91){ //Buchstabe groß Buchstabe
|
||||
ascii_offset = 65;
|
||||
SR_Buffer[pos] = character_Font[character - ascii_offset]; //Zieht ASCII-Offset ab, sodass Buchstaben mit Font Index übereinstimmen
|
||||
} else if (character == 32){ //Charakter ist Blank ' '
|
||||
SR_Buffer[pos] = blank;
|
||||
} else if (character == 45){ //Charakter ist Minus -
|
||||
SR_Buffer[pos] = minus;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void add_Character_to_SR_Buffer(unsigned char character, int pos) {
|
||||
int ascii_offset = 0;
|
||||
|
||||
if (character > 96 && character < 122) { //Buchstabe ist kleiner Buchstabe
|
||||
ascii_offset = 97;
|
||||
SR_Buffer[pos] = character_Font[character - ascii_offset]; //Zieht ASCII-Offset ab, sodass Buchstaben mit Font Index übereinstimmen
|
||||
} else if (character > 65 && character < 91){ //Buchstabe groß Buchstabe
|
||||
ascii_offset = 65;
|
||||
SR_Buffer[pos] = character_Font[character - ascii_offset]; //Zieht ASCII-Offset ab, sodass Buchstaben mit Font Index übereinstimmen
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void add_Number_to_SR_Buffer(int number, int pos) {
|
||||
SR_Buffer[pos-1] = number_Font[number];
|
||||
}
|
||||
87
code/src/uart.c
Normal file
87
code/src/uart.c
Normal file
@@ -0,0 +1,87 @@
|
||||
#include <avr/io.h>
|
||||
#include "uart.h"
|
||||
|
||||
|
||||
|
||||
void USART_Init(unsigned int ubrr)
|
||||
{
|
||||
/*Set baud rate */
|
||||
UBRR0H = ubrr>>8;
|
||||
UBRR0L = ubrr;
|
||||
/*Enable receiver and transmitter */
|
||||
UCSR0B = (1<<TXEN0);
|
||||
//| (1<<RXEN0)
|
||||
//|(1<<RXCIE0);
|
||||
/* Set frame format: 8data, 1 stop bit */
|
||||
UCSR0C = (1<<UCSZ00) | (1 << UCSZ01);
|
||||
}
|
||||
|
||||
void USART_Transmit(unsigned char data )
|
||||
{
|
||||
/* Wait for empty transmit buffer */
|
||||
while ( !( UCSR0A & (1<<UDRE0)) )
|
||||
;
|
||||
/* Put data into buffer, sends the data */
|
||||
UDR0 = data;
|
||||
}
|
||||
|
||||
void uart_puts(char * str) {
|
||||
while (*str) {
|
||||
putchar(*str++);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int putchar(int c){
|
||||
USART_Transmit((char) c);
|
||||
//while ( !( UCSR0A & (1<<UDRE0)) )
|
||||
//UDR0 = c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
void search_i2c_devices(){
|
||||
char error, address;
|
||||
int nDevices;
|
||||
|
||||
uart_puts("Scanning...");
|
||||
|
||||
|
||||
nDevices = 0;
|
||||
for (address = 1; address < 127; address++ )
|
||||
{
|
||||
uart_puts("\n");
|
||||
uart_puts("Scanning...");
|
||||
// The i2c_scanner uses the return value of
|
||||
// the Write.endTransmisstion to see if
|
||||
// a device did acknowledge to the address.
|
||||
i2c_start_wait(address);
|
||||
error = i2c_readNak();
|
||||
|
||||
if (error == 0)
|
||||
{
|
||||
uart_puts("I2C device found at address 0x");
|
||||
if (address < 16)
|
||||
uart_puts("0");
|
||||
uart_puts(address);
|
||||
uart_puts(" !");
|
||||
|
||||
nDevices++;
|
||||
}
|
||||
else if (error == 4)
|
||||
{
|
||||
uart_puts("Unknown error at address 0x");
|
||||
if (address < 16)
|
||||
uart_puts("0");
|
||||
uart_puts(address);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
uart_puts("No I2C devices found\n");
|
||||
else
|
||||
uart_puts("done\n");
|
||||
|
||||
// delay(); // wait 5 seconds for next scan
|
||||
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user