Compare commits

...

3 Commits

View File

@@ -8,19 +8,12 @@
//**********************************************************************
//**********************************************************************
#include <at89c55.h>
#include <at89c51ed2.h>
#include <stdio.h>
#include <stdint.h>
#define TICK_RATE 100
#define NPER (0x10000 - (20000000 / 12 / TICK_RATE))
// Missing port definitions
__sbit __at (0xC4) P4_4;
__sbit __at (0xC3) P4_3;
__sbit __at (0xC2) P4_2;
__sbit __at (0xC1) P4_1;
__sbit __at (0xC0) P4_0;
#define NPER (0x10000 - (20000000 / 6 / TICK_RATE))
// I/O definitions
#define BUTTON_1 P3_2
@@ -71,8 +64,7 @@ uint8_t lcd_pos;
// Quick'n'dirty CPU pause, just enough for the LCD to stabilize.
void lcd_pause(void) {
int i = 30;
while(i--);
__asm__ ("nop");
}
// Reads the status register from the LCD.
@@ -170,11 +162,8 @@ void lcd_init(void) {
// Puts a character to the LCD. Correctly handles '\n'.
void lcd_putchar(char c) {
if(c == 10) {
while((lcd_pos != 0) && (lcd_pos != 40)) {
lcd_send_data(32);
lcd_pos++;
if(lcd_pos == 80) lcd_pos=0;
}
if(lcd_pos < 40) lcd_pos = 40;
else lcd_pos = 0;
} else {
lcd_send_data(c);
lcd_pos++;
@@ -184,6 +173,8 @@ void lcd_putchar(char c) {
// Initializes the background tick timer (for delays).
void timer_init(void) {
CKCON0 = X2; // Enable 2x clock mode
// Initialize timer 0 as 16-bit countdown, timer 1 as 8-bit auto-reload countdown
TMOD = 0x21;
@@ -204,7 +195,7 @@ void serial_init(void) {
// Initialize timer 2 as 312500 Hz as the baud rate generator (for tulflash)
RCAP2H = 0xFF;
RCAP2L = 0xFE;
RCAP2L = 0xFC;
T2CON = 0x34;
// Initialize serial I/O
@@ -296,6 +287,8 @@ void main(void) {
lcd_init();
serial_init();
delay(1);
stdout_to_serial = 1;
stdout_to_lcd = 1;