I am trying to write a basic program to transmit character 1 to a pc. below is my code.
I have set the 9600 baud rate on brays terminal and the correct stop bits data bits, by default the uC is 8 data bits no parity and 1 stop bit. All I get on brays is a continuous stream of 0><0><0><0><0><0><0><0><0><0><0
Any thoughts?, this is very basic and I am disappointed that I cant seem to get it working
MOD note: Added code tags.
C:
#define F_CPU 20000000UL // Clock Frequency
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
#define Bd_Rate 9600UL // define baud
#define Bd_Reg (F_CPU / (16 * Bd_Rate)) - 1 // set baudrate value for UBRR
#define timeperiod (1/(F_CPU)) // at a clock of 20MHZ this gives time period of 0.05uS. For one bit of length 70us need the timer to = 70/0.05 = 1400.
void Tx_Character (char data)
{
while (!( UCSR0A & (1<<UDRE0))); // wait while register is free
UDR0 = data; // load data in the register
}
int main (void)
{
sei(); // enable global interrupts
UBRR0 = 129; // set the baud rate
UCSR0B |= 1<<TXEN0 | 1<<TXCIE0 ; // enable transmitter and interuppt for usart
DDRD = 0xFF; // All outputs
while(1){
asm("nop");
Tx_Character('1');
}
}
Any thoughts?, this is very basic and I am disappointed that I cant seem to get it working
MOD note: Added code tags.
Last edited by a moderator: