by vivat » Mon Nov 26, 2007 5:25 pm
Below are some code snippets that can be used in order to test your LCD with the TC553/852 controller and Atmega16 micro. Make sure you connect RxD and TxD from TC553/852 controller to TxD and RxD on Atmega16 and use a common ground (GND). For a connection diagram refer to the most up-to-date TC553/852 Controller
User Manual.
Code: Select all
/* uart_rx is a global
use interrupt handler to update
example
#pragma interrupt_handler uart0_rx_isr:12
void uart0_rx_isr(void)
{
//uart has received a character in UDR
uart_rx = getchar();
}
don't forget to set up UART
*/
// *****************************************************************************
void wait_for_response(void)
{
uart_rx = 0;
while(uart_rx == 0);
}
// *****************************************************************************
void clear_screen(void)
{
printf("%c",1); // clear screen
printf("%c",1); // clear screen
wait_for_response();
}
// *****************************************************************************
void start_p_c(char page, char column)
{
printf("%c",6); // start page
printf("%c",page); // page number
printf("%c",18); // start column
printf("%c",column); // column number
wait_for_response();
}
// *****************************************************************************
void line_draw(char start_x, char start_y, char stop_x, char stop_y)
{
printf("%c",30); // line
printf("%c",0); // draw
printf("%c",start_x); // start x
printf("%c",start_y); // start y
printf("%c",stop_x); // stop x
printf("%c",stop_y); // stop y
wait_for_response();
}
// *****************************************************************************
void rectangle_draw(char rectangle, char start_x, char start_y, char stop_x, char stop_y)
{
printf("%c",30); // rectangle
printf("%c",rectangle); // draw
printf("%c",start_x); // start x
printf("%c",start_y); // start y
printf("%c",stop_x); // stop x
printf("%c",stop_y); // stop y
wait_for_response();
}
// *****************************************************************************
void font_select(char font)
{
printf("%c",21); // font select
printf("%c",font); // font
wait_for_response();
}
// *****************************************************************************
void print_font(char font)
{
printf("%c",2); // text mode
printf("%c",font); // font
wait_for_response();
}
// *****************************************************************************
void hello(void)
{
char message[5]= {'H','e','l','l','o'};
char i;
int k;
for(i=0;i<5;i++)
{
print_font(message[i]);
for(k=0;k<3000;k++); //delay
}
}
// *****************************************************************************
void main(void)
{
init_devices();
uart_rx = 0;
clear_screen();
line_draw(62,0,62,63); //line from 62,0 to 62,63
line_draw(63,0,63,63); //line from 63,0 to 63,63
line_draw(0,31,127,31); //line from 0,31 to 127,31
font_select(1); // 1 for font 5x7, 2 for font 8x14, 3 for font 8x14 Bold
start_p_c(1,5); // page,column
hello();
font_select(2); // 1 for font 5x7, 2 for font 8x14, 3 for font 8x14 Bold
start_p_c(1,70); // page,column
hello();
font_select(3); // 1 for font 5x7, 2 for font 8x14, 3 for font 8x14 Bold
start_p_c(5,5); // page,column
hello();
start_p_c(5,70); // page,column
hello();
rectangle_draw(3, 69, 40, 101, 55);// box, start_x, start_y, stop_x, stop_y
}
Below are some code snippets that can be used in order to test your LCD with the TC553/852 controller and Atmega16 micro. Make sure you connect RxD and TxD from TC553/852 controller to TxD and RxD on Atmega16 and use a common ground (GND). For a connection diagram refer to the most up-to-date TC553/852 Controller [url=http://www.tvielectronics.com/Documents/TC553852UM.pdf]User Manual[/url].
[code]/* uart_rx is a global
use interrupt handler to update
example
#pragma interrupt_handler uart0_rx_isr:12
void uart0_rx_isr(void)
{
//uart has received a character in UDR
uart_rx = getchar();
}
don't forget to set up UART
*/
// *****************************************************************************
void wait_for_response(void)
{
uart_rx = 0;
while(uart_rx == 0);
}
// *****************************************************************************
void clear_screen(void)
{
printf("%c",1); // clear screen
printf("%c",1); // clear screen
wait_for_response();
}
// *****************************************************************************
void start_p_c(char page, char column)
{
printf("%c",6); // start page
printf("%c",page); // page number
printf("%c",18); // start column
printf("%c",column); // column number
wait_for_response();
}
// *****************************************************************************
void line_draw(char start_x, char start_y, char stop_x, char stop_y)
{
printf("%c",30); // line
printf("%c",0); // draw
printf("%c",start_x); // start x
printf("%c",start_y); // start y
printf("%c",stop_x); // stop x
printf("%c",stop_y); // stop y
wait_for_response();
}
// *****************************************************************************
void rectangle_draw(char rectangle, char start_x, char start_y, char stop_x, char stop_y)
{
printf("%c",30); // rectangle
printf("%c",rectangle); // draw
printf("%c",start_x); // start x
printf("%c",start_y); // start y
printf("%c",stop_x); // stop x
printf("%c",stop_y); // stop y
wait_for_response();
}
// *****************************************************************************
void font_select(char font)
{
printf("%c",21); // font select
printf("%c",font); // font
wait_for_response();
}
// *****************************************************************************
void print_font(char font)
{
printf("%c",2); // text mode
printf("%c",font); // font
wait_for_response();
}
// *****************************************************************************
void hello(void)
{
char message[5]= {'H','e','l','l','o'};
char i;
int k;
for(i=0;i<5;i++)
{
print_font(message[i]);
for(k=0;k<3000;k++); //delay
}
}
// *****************************************************************************
void main(void)
{
init_devices();
uart_rx = 0;
clear_screen();
line_draw(62,0,62,63); //line from 62,0 to 62,63
line_draw(63,0,63,63); //line from 63,0 to 63,63
line_draw(0,31,127,31); //line from 0,31 to 127,31
font_select(1); // 1 for font 5x7, 2 for font 8x14, 3 for font 8x14 Bold
start_p_c(1,5); // page,column
hello();
font_select(2); // 1 for font 5x7, 2 for font 8x14, 3 for font 8x14 Bold
start_p_c(1,70); // page,column
hello();
font_select(3); // 1 for font 5x7, 2 for font 8x14, 3 for font 8x14 Bold
start_p_c(5,5); // page,column
hello();
start_p_c(5,70); // page,column
hello();
rectangle_draw(3, 69, 40, 101, 55);// box, start_x, start_y, stop_x, stop_y
}[/code]