diff --git a/Makefile b/Makefile index 9656d51..7d0d67f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ SDCC ?= sdcc SDAR ?= sdar STCCODESIZE ?= 8192 -SDCCOPTS ?= -mmcs51 --iram-size 512 --code-size $(STCCODESIZE) --xram-size 0 --opt-code-size --stack-auto +SDCCOPTS ?= -mmcs51 SDCCREV ?= -Dstc15f204ea STCGAL ?= stcgal #/stcgal.py @@ -13,7 +13,7 @@ FLASHFILE ?= main.ihx #FOSC ?=11056000L CFLAGS ?= -DWITH_ALT_LED9 -DWITHOUT_LEDTABLE_RELOC -DSHOW_TEMP_DATE_WEEKDAY -LIBSRC = uart_init.c uart_send_chr.c uart_send_str.c \ +LIBSRC = uart_init_.c uart_send_chr.c uart_send_str.c \ rotary_encoder_stat.c \ sevenseg_dec.c sevenseg_dec_inv.c \ int_to_bcd.c getbutton.c diff --git a/mc8051fun.h b/mc8051fun.h index 71e274b..857a1aa 100644 --- a/mc8051fun.h +++ b/mc8051fun.h @@ -6,12 +6,19 @@ - - -void uart_init(long fosc, long baud); void uart_send_chr(char tx_data); void uart_send_str(const char *str); +void uart_init_(uint8_t timer_init,uint8_t x2); + +#define uart_init(baud,x2) \ + uart_init_(256L-FOSC/12L/(baud*16L/(1< -#include - -void uart_init(long fosc, long baud) -{ - TMOD |= 0x20; // Timer 1 in Mode 2 - TH1 = 0xFD; // 9600 baud rate - TL1 = 0xFD; // Initial value (not necessary) - TR1 = 1; // Start Timer 1 - SCON = 0x50; // 8-bit data, 1 stop bit, REN enabled - return; - - - TMOD = 0; /* Timer 1, 8-bit auto reload mode */ - // P_SW1 |= (1 << 6); // move UART1 pins -> P3_6:rxd, P3_7:txd - - // UART1 use Timer2 -// T2L = (65536 - (fosc / 4 / baud)) & 0xFF; -// T2H = (65536 - (fosc / 4 / baud)) >> 8; - - SM0 = 0; - SM1 = 1; // serial mode 1: 8-bit async -// AUXR |= 0x14; // T2R: run T2, T2x12: T2 clk src sysclk/1 -// AUXR |= 0x01; // S1ST2: T2 is baudrate generator - SCON = 0x50; - - TMOD |= T1_M1; - TI=1; - TCLK=0; - RCLK=0; -// TBCK=0; -// RBCK=0; -// - TH1=0xFD; - - - //SMOD0=0; - - ES = 1; // enable uart1 interrupt - EA = 1; // enable interrupts - REN = 1; - - - -} - - diff --git a/uart_init_.c b/uart_init_.c new file mode 100644 index 0000000..b64a1f2 --- /dev/null +++ b/uart_init_.c @@ -0,0 +1,23 @@ +#include "mc8051fun.h" + +#include + + +void uart_init_(uint8_t timer_init,uint8_t x2) +{ + TMOD |= 0x20; // Timer 1 in Mode 2 + TH1 = timer_init; + TL1 = timer_init; + TR1 = 1; // Start Timer 1 + SCON = 0x50; // 8-bit data, 1 stop bit, REN enabled + + if(x2) + setbits(PCON,SMOD); + else + unsetbits(PCON,SMOD); + + return; + +} + +