You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.1 KiB
67 lines
1.1 KiB
#ifdef DEBUG
|
|
#include "usart.h"
|
|
|
|
void initUSART(){
|
|
UBRR0 = (unsigned char) MYUBRR;
|
|
|
|
/*enable USART write and read*/
|
|
UCSR0B |= /*(1<<RXCIE)|*/(1<<RXEN0)|(1<<TXEN0);
|
|
/*odd parity, 1 stop bit, 8bit words*/
|
|
UCSR0C |= (1<<UPM01)|(1<<UPM00)|(1<<UCSZ01)|(1<<UCSZ00);
|
|
}
|
|
|
|
void tx( char data ){
|
|
while ( !( UCSR0A & (1<<UDRE0)) );
|
|
UDR0 = data;
|
|
}
|
|
|
|
void sendstr( char* str){
|
|
while(str[0]!=0){
|
|
tx(str[0]);
|
|
str++;
|
|
}
|
|
}
|
|
|
|
void sendunum(uint32_t num){
|
|
char text[11] = {0,0,0,0,0,0,0,0,0,0,0};
|
|
uint32_t tmp=1;
|
|
char leadingzero=0;
|
|
char digit=0;
|
|
char i;
|
|
if(num==0){
|
|
tx('0');
|
|
return;
|
|
}
|
|
for(i=1;i<=10;i++){
|
|
digit = '0'+((num/tmp)%10);
|
|
tmp*=10;
|
|
if(digit=='0'){
|
|
leadingzero++;
|
|
}else{
|
|
leadingzero=0;
|
|
}
|
|
text[10-i]=digit;
|
|
}
|
|
sendstr( text+leadingzero );
|
|
}
|
|
|
|
void tx_hex(uint8_t c){
|
|
if( ((c&0xF0)>>4) <0x0A ){
|
|
tx('0'+((c&0xF0)>>4) );
|
|
}else{
|
|
tx('A'-0x0A+((c&0xF0)>>4));
|
|
}
|
|
|
|
if( (c&0x0F)<0x0A ){
|
|
tx('0'+(c&0x0F));
|
|
}else{
|
|
tx('A'-0x0A+(c&0x0F));
|
|
}
|
|
}
|
|
|
|
char rx( void ){
|
|
while ( !(UCSR0A & (1<<RXC0)) );
|
|
return UDR0;
|
|
}
|
|
#endif //DEBUG
|
|
|
|
|