support avr architecture based on ATMega32

1. IAR project, see TencentOS-tiny\board\ATMega32\IAR, both 4.12 and 7.20 is supplied.
This commit is contained in:
daishengdong
2020-03-03 18:27:24 +08:00
parent e3da94194e
commit 7e6ce005e6
56 changed files with 13225 additions and 244 deletions

View File

@@ -0,0 +1,47 @@
#include "iom32.h"
#include "uart.h"
#define F_CPU 16777216
void uart_send_byte(char data)
{
while (!(UCSRA & (1 << UDRE))) {
;
}
UDR = data;
}
void uart_send_string(char *string)
{
for(; *string!='\0'; string++) {
uart_send_byte(*string);
}
}
unsigned char uart_receive(void)
{
while (!(UCSRA & (1 << RXC))) {
;
}
return UDR;
}
int putchar(int data)
{
uart_send_byte(data);
}
void uart_init(unsigned int baudrate)
{
unsigned int tmp;
tmp = F_CPU / baudrate / 16 - 1;
/* Set baud rate */
UBRRH = (unsigned char)(tmp >> 8);
UBRRL = (unsigned char)tmp;
/* Enable receiver and transmitter, enable receive interrupt */
UCSRB = (1 << RXCIE) | (1 << RXEN) | (1 << TXEN);
/* 8bit, 1 stopbit */
UCSRC = (1 << URSEL) | (1 << UCSZ1) | (1<< UCSZ0);
}