I am using AVR C with Atmega micro controller. I am using serial communication, I want to transmit a char "A" to screen and then erase it and display "B". I am having troubling with clearing the screen.
I read that ESC ASCII can work so I tried.
#define F_CPU 16000000UL
void initUART(unsigned int baud);
void transmitByte(unsigned char data);
unsigned char receiveByte(void);
int getNumOfDigits(int num);
void printDec(int num);
int main(void) {
DDRB = 0b00000011;
PORTB = 0b00011000;
initUART(9600);
while(1) {
//s1 pressed
if ((PINB & 0b00001000) == 0) {
transmitByte('A');
transmitByte((char) 27);
transmitByte('B');
_delay_ms(1000);
}
}
return 0;
}
void initUART(unsigned int baud) {
/*
Initialize settings for uart functions.
Must be done once at the beginning of the program.
*/
//Normal mode UBRR formula
unsigned int ubrr = F_CPU/16/baud-1;
//shift MSB and store in UBRR0H
UBRR0H = (unsigned char) (ubrr >> 8);
//store LSB in UBRR0L
UBRR0L = (unsigned char) ubrr;
//Enable transmitter/receiver
UCSR0B = (1 << RXEN0) | (1 << TXEN0);
//8-Bit Characters, 0 Stop bits, No parity
UCSR0C = (1 << UCSZ00) | (1 << UCSZ01);
}
void transmitByte(unsigned char data) {
/*
Write byte to UART
*/
//Wait for empty transmit buffer
while(!(UCSR0A & (1 << UDRE0)));
//Start transmission by writing to UDR0
UDR0 = data;
}
unsigned char receiveByte(void){
/*
Read byte from UART
*/
//Wait for incoming byte
while(!(UCSR0A & (1 << RXC0)));
//Return the byte
return UDR0;
}
But its not working, I am fairly new to micro-controller, it just prints
AAAA..
How do I clear screen and then print a new character on the serial communication screen, I am using putty.
Update
transmitByte('A');
transmitByte(27); // this is the escape
transmitByte('[');
transmitByte('2');
transmitByte('J'); // uppercase J
transmitByte('^');
transmitByte('[');
transmitByte('H');
transmitByte('B');
Output
How do I get the cursor back to its orignal position?
Final Working
transmitByte('A');
transmitByte(27); // this is the escape
transmitByte('[');
transmitByte('2');
transmitByte('J'); // uppercase J
transmitByte(27);
transmitByte('[');
transmitByte('H');
transmitByte('B');
Above code works, erase and the moves the cursor back.