![Page 1: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/1.jpg)
Optrex LCD in NIOSOptrex LCD in NIOS
![Page 2: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/2.jpg)
Page 2
Optrex LCD introductionOptrex 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
![Page 3: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/3.jpg)
Page 3
Functional DescriptionFunctional Description
E—Enable (output)
RS—Register Select (output)
R/W—Read or Write (output)
DB0 through DB7—Data Bus (bidirectional)
![Page 4: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/4.jpg)
Page 4
Source and header filesSource 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
![Page 5: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/5.jpg)
Page 5
Register mapRegister map
![Page 6: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/6.jpg)
Page 6
LCD register I/OLCD 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
![Page 7: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/7.jpg)
Page 7
Command wordsCommand 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 */
![Page 8: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/8.jpg)
Page 8
Write command word to LCDWrite 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}
![Page 9: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/9.jpg)
Page 9
Write data to LCDWrite 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;}
![Page 10: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/10.jpg)
Page 10
LCD coordinates and display LCD coordinates and display addressesaddresses
Display cell in LCD is identified by display address
Address(x,y)= x+colstart[y] x: column y: row colstart[2] = { 0x00, 0x40}
A B C D …
![Page 11: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/11.jpg)
Page 11
LCD display bufferLCD 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
![Page 12: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/12.jpg)
Page 12
Data structure of display bufferData 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;
![Page 13: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/13.jpg)
Page 13
Update display bufferUpdate 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
![Page 14: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/14.jpg)
Page 14
Write character to LCDWrite 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=<character to be output> lcd_write_command(base,command) // Write command to command register lcd_write_data(base,character)// Write data to data register <Update display buffer>
![Page 15: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/15.jpg)
Page 15
Write character to LCDWrite 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;}
![Page 16: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/16.jpg)
Page 16
Clear ScreenClear 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]=' ';
}
}
}
![Page 17: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/17.jpg)
Page 17
Repaint ScreenRepaint 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;}
![Page 18: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/18.jpg)
Page 18
Scroll ScreenScroll 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;}
![Page 19: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/19.jpg)
Page 19
Control CharactersControl 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
![Page 20: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/20.jpg)
Page 20
Handle new line character ‘\n’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
![Page 21: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/21.jpg)
Page 21
Handle backspace character ‘\b’Handle backspace character ‘\b’
Pseudo code: if characer=‘\b’ if ( cursor doesn’t located at the start of line ) coordinate.x++ else do nothing
![Page 22: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/22.jpg)
Page 22
SummarySummary
JTAR UART on DE2 board Introduction HAL supports Register file and register access Interrupts
![Page 23: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/23.jpg)
Page 23
HW2 answer keysHW2 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)
![Page 24: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/24.jpg)
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
![Page 25: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/25.jpg)
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
![Page 26: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/26.jpg)
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
![Page 27: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/27.jpg)
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
![Page 28: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/28.jpg)
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
![Page 29: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/29.jpg)
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
![Page 30: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/30.jpg)
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
![Page 31: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/31.jpg)
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
![Page 32: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/32.jpg)
Page 32
10 A UART is an example of a synchronous serial interface
FALSE
![Page 33: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/33.jpg)
Page 33
12 [a] What is a serial portcommunication interface connects serial I/O devices and
serial I/O on board [b] Give a real world example of serial port USB port
![Page 34: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/34.jpg)
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)
![Page 35: Optrex LCD in NIOS. Page 2 Optrex LCD introduction The Optrex 16207 LCD controller core with Avalon® Interface (LCD controller core) provides the hardware](https://reader036.vdocument.in/reader036/viewer/2022081421/56649d805503460f94a65135/html5/thumbnails/35.jpg)
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