Presentation is loading. Please wait.

Presentation is loading. Please wait.

Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware.

Similar presentations


Presentation on theme: "Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware."— Presentation transcript:

1 Optrex LCD in NIOS

2 Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware interface and software driver required for a Nios® II processor to display characters on an Optrex 16207 (or equivalent) 16×2-character LCD panel

3 Page 3 Functional Description E—Enable (output) RS—Register Select (output) R/W—Read or Write (output) DB0 through DB7—Data Bus (bidirectional)

4 Page 4 Source and header files altera_avalon_lcd_16207_regs.h — This file defines the core's register map, providing symbolic constants to access the low-level hardware. altera_avalon_lcd_16207.h, altera_avalon_lcd_16207.c — These files implement the LCD controller device drivers for the HAL system library

5 Page 5 Register map

6 Page 6 LCD register I/O IOADDR_ALTERA_AVALON_LCD_16207_COMMAND(base) Write to command register IORD_ALTERA_AVALON_LCD_16207_STATUS(base) Read from status register IOWR_ALTERA_AVALON_LCD_16207_DATA(base, data) IORD_ALTERA_AVALON_LCD_16207_DATA(base) Write to/ Read from data register

7 Page 7 Command words LCD_CMD_WRITE_DATA = 0x80 /* Bits 6:0 hold character RAM address */ LCD_CMD_ONOFF = 0x08, LCD_CMD_ENABLE_DISP = 0x04, LCD_CMD_ENABLE_CURSOR = 0x02, LCD_CMD_ENABLE_BLINK = 0x01 /* On/Off command */ LCD_CMD_CLEAR = 0x01 /* Clear command */

8 Page 8 Write command word to LCD static int lcd_write_command(unsigned char * base, unsigned char command) { int i = 1000000; /* Wait until LCD isn't busy. */ while (IORD_ALTERA_AVALON_LCD_16207_STATUS(base) & ALTERA_AVALON_LCD_16207_STATUS_BUSY_MSK) if (--i == 0) return 0; usleep(100); IOWR_ALTERA_AVALON_LCD_16207_COMMAND(base, command); return 1 }

9 Page 9 Write data to LCD static int lcd_write_data(unsigned char * base, unsigned char data) { int i = 1000000; while (IORD_ALTERA_AVALON_LCD_16207_STATUS(base) & ALTERA_AVALON_LCD_16207_STATUS_BUSY_MSK) if (--i == 0) return 0; usleep(100); IOWR_ALTERA_AVALON_LCD_16207_DATA(base, data); return 1; }

10 Page 10 LCD coordinates and display addresses Display cell in LCD is identified by display address Address(x,y)= x+colstart[y] x: column y: row colstart[2] = { 0x00, 0x40} ABCD…

11 Page 11 LCD display buffer Display buffer is located in memory, storing the displayed contents on LCD screen Dynamically updated by software Keep LCD display in memory, provide a convenient way to read data from LCD

12 Page 12 Data structure of display buffer #define MAX_WIDTH 16 #define MAX_HEIGHT 2 struct lcd_buffer_type { int x,y; // Current display coordinate char buffer[MAX_HEIGHT][MAX_WIDTH]; // Buffer } lcd_buffer;

13 Page 13 Update display buffer When sending command to LCD, corresponding display buffer status also need to be updated Writing character to LCD Screen scrolling Screen clearing Special character: \t, \b, \n

14 Page 14 Write character to LCD command=LCD_CMD_WRITE_DATA | (x+colstart[y]) Compose write command word, lower 6 bits are the display address of the character character= lcd_write_command(base,command) // Write command to command register lcd_write_data(base,character) // Write data to data register

15 Page 15 Write character to LCD static int lcd_print_char(unsigned char * base, int y, int x, unsigned char c) { unsigned char command=0; command=LCD_CMD_WRITE_DATA | (x+colstart[y]); lcd_write_command(base,command); lcd_write_data(base,c); lcd_buffer.buffer[y][x]=c; }

16 Page 16 Clear Screen static void lcd_clear_screen(unsigned char * base) { int y; int i,j; lcd_write_command(base, LCD_CMD_CLEAR); lcd_buffer.x=0; lcd_buffer.y=0; for(i=0;i<MAX_HEIGHT;i++) { for(j=0;j<MAX_WIDTH;j++) { lcd_buffer.buffer[i][j]=' '; }

17 Page 17 Repaint Screen static int lcd_repaint(unsigned char * base) { int i,j; for(i=0;i<MAX_WIDTH;i++) { for(j=0;j<MAX_HEIGHT;j++) { lcd_print_char(base,j,i,lcd_buffer.buffer[j][i]); } return 1; }

18 Page 18 Scroll Screen static int lcd_scroll_up(unsigned char *base) { int i,j; for(i=0;i<MAX_WIDTH;i++) { lcd_buffer.buffer[0][i]=lcd_buffer.buffer[1][i]; lcd_buffer.buffer[1][i]=' '; } lcd_repaint(base); return 1; }

19 Page 19 Control Characters Special character used to control display format ‘\n’: New line ‘\b’: backspace … When print control characters on LCD, updating need to be applied to both LCD screen and display buffer

20 Page 20 Handle new line character ‘\n’ Pseudo code: if characer=‘\n’ if ( cursor doesn’t reach the bottom of the screen ) coordinate.y++ coordinate.x=0 else coordinate.x=0 scroll screen up one line

21 Page 21 Handle backspace character ‘\b’ Pseudo code: if characer=‘\b’ if ( cursor doesn’t located at the start of line ) coordinate.x++ else do nothing

22 Page 22 Summary JTAR UART on DE2 board Introduction HAL supports Register file and register access Interrupts

23 Page 23 HW2 answer keys 1 [a] what is the purpose of I/O on a board Moving information into and out of the board to I/O devices [b] List five categories of board I/O, with two real-world examples under each category Networking and communication I/O (wireless & wire network card) Input(keyboard mouse) Graphic and output I/O(touch screen, CRT) Storage I/O (hard drive, CD ROM) Debugging I/O (BDM, JTAG)

24 Page 24 2 Name and describe the six logical units into which I/O hardware can be classified Transmission medium Communication port Communication interface I/O controller I/O buses Master processor integrated I/O

25 Page 25 3 In figure 6-26a and b indicate what I/O component fall under what I/O logical unit Look at page 255 Figure 6-3 a and b

26 Page 26 4 [a] what is the difference between serial and parallel I/O Serial: data are transferred one bit at a time Parallel: multiple bits simutaneously [b] Give a real world I/O example of each Serial: RS-232 Parallel: PCI

27 Page 27 5 [a] What is the difference between simplex, half-duplex and full duplex Simplex: one way only Half duplex: bidirection, but one direction only at a time Full duplex: bidirection anytime [b] Indicate which transmission scheme is shown in Figure 6-27a,b,c Look at Figure 6-4a,b,c

28 Page 28 6 [a] what is asynchronous transfer of serial data Data are transferred intermittently at irregular intervals [b] Draw a diagram that describes how asynchronous transfer of serial data works Figure 6-5

29 Page 29 7 The baud rate is A. the bandwidth of the serial interface B. the total number of bits that can be transmitted C. the total number of bits per unit time that can be transmitted D. None of above C

30 Page 30 What is the bit rate of a serial interface A measurement for the data transmission rate Write the equation Number of actual data bits per frame/total number of bits per frame* baud rate

31 Page 31 9 [a] what is synchronous transfer of serial data Data transmission is regulated by CPU’s clock [b] Draw and describe how synchronous transfer of serial data works Figure 6-6

32 Page 32 10 A UART is an example of a synchronous serial interface FALSE

33 Page 33 12 [a] What is a serial port communication interface connects serial I/O devices and serial I/O on board [b] Give a real world example of serial port USB port

34 Page 34 [20] How board I/O negatively impact a system’s performance Slow I/O will make processor waiting for data in most cycles Fast I/O will not be efficient when combined with a slow CPU Synchronization between CPU and I/O Strategy for I/O communication (polling<interrupt<DMA)

35 Page 35 21 If there is no mechanism to synchronize the speed differences between I/O devices and the master CPU A. data will lost B. nothing can go wrong C. the entire system could crush D. A and C only E None of the above D


Download ppt "Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware."

Similar presentations


Ads by Google