Docsity

Assembly Language Subroutines for LCD Control and Delay, Assignments of Microprocessors

Toggle sidebar
bg1
Homework 4 ECE 2534
Write an assembly language subroutine named LCD_write that writes a command
or data byte to the LCD. This subroutine is intended be called from the C program
below. The subroutine is called with an integer and a char. The integer indicates whether
a command (0) or data (4) byte is to be written. The char contains the byte to be written.
Information on the commands and timing for the LCD peripheral are contained in
chapter 5 of the Spartan-3E Starter Kit Board User Guide. Since the LCD peripheral is
initialized when the board is powered up, you shouldn’t have to worry about power-on
initialization.
Also write an assembly language subroutine called sleep to delay a specified
number of microseconds. We will have use for a general-purpose delay routine callable
from C in the future.
/*
Program: Test LCD
Created by: WTB
Description: Writes test strings to the LCD and displays rotary count. 0-1 transition on SW3 clears count
Last Modified: 2/16/09
*/
//Prototypes
void LCD_char(int index, char letter);
extern "C" void LCD_write (int cmd_data, char data);
extern "C" int Rotary(void);
extern "C" int Button_Push(int mask);
extern "C" void AsmInit(void);
extern "C" void sleep(int usec);
//Defines
#define CMD 0
#define DATA 4
#define LCD_clear() LCD_write(CMD,1)
int main(void) {
int ind,count,temp;
AsmInit(); //initialize any required ASM variables
LCD_clear(); //clear LCD
sleep(1640); //wait for command to execute
for(ind=0;ind<16;ind++) LCD_char(ind,"Embedded systems"[ind]);//write first string
for(ind=0;ind<9;ind++) LCD_char(ind+0x41,"are cool!"[ind]); //write second string
count=0;
while (1) {
count += Rotary(); //increment count based on rotary knob movement
if (count>=100) count=0;
if (count<0) count=0;
if (Button_Push(0x8)) count=0; //clear count based on switch movement
temp=count/10;
LCD_char(0x4d,'0'+temp); //write 10's digit of count
LCD_char(0x4e,'0'+count-10*temp);
}
}
void LCD_char(int index, char letter) {
LCD_write(CMD,(char)(0x80|index));
LCD_write(DATA,letter);
}
The relevant addresses for the control and data registers of the LCD are:
pf3

Partial preview of the text

Download Assembly Language Subroutines for LCD Control and Delay and more Assignments Microprocessors in PDF only on Docsity!

Homework 4 ECE 2534

Write an assembly language subroutine named LCD_write that writes a command

or data byte to the LCD. This subroutine is intended be called from the C program

below. The subroutine is called with an integer and a char. The integer indicates whether

a command (0) or data (4) byte is to be written. The char contains the byte to be written.

Information on the commands and timing for the LCD peripheral are contained in

chapter 5 of the Spartan-3E Starter Kit Board User Guide. Since the LCD peripheral is

initialized when the board is powered up, you shouldn’t have to worry about power-on

initialization.

Also write an assembly language subroutine called sleep to delay a specified

number of microseconds. We will have use for a general-purpose delay routine callable

from C in the future.

Program: Test LCD Created by: WTB Description: Writes test strings to the LCD and displays rotary count. 0-1 transition on SW3 clears count Last Modified: 2/16/ / //Prototypes void LCD_char(int index, char letter); extern "C" void LCD_write (int cmd_data, char data); extern "C" int Rotary(void); extern "C" int Button_Push(int mask); extern "C" void AsmInit(void); extern "C" void sleep(int usec); //Defines #define CMD 0 #define DATA 4 #define LCD_clear() LCD_write(CMD,1) int main(void) { int ind,count,temp; AsmInit(); //initialize any required ASM variables LCD_clear(); //clear LCD sleep(1640); //wait for command to execute for(ind=0;ind<16;ind++) LCD_char(ind,"Embedded systems"[ind]);//write first string for(ind=0;ind<9;ind++) LCD_char(ind+0x41,"are cool!"[ind]); //write second string count=0; while (1) { count += Rotary(); //increment count based on rotary knob movement if (count>=100) count=0; if (count<0) count=0; if (Button_Push(0x8)) count=0; //clear count based on switch movement temp=count/10; LCD_char(0x4d,'0'+temp); //write 10's digit of count LCD_char(0x4e,'0'+count-10temp); } } void LCD_char(int index, char letter) { LCD_write(CMD,(char)(0x80|index)); LCD_write(DATA,letter); }

The relevant addresses for the control and data registers of the LCD are:

.equ LCD_CONT, 0x

# unused LCD_E|LCD_RS|LCD_RW|AD_CONV Keep AD_CONV low

.equ LCD_DATA, 0x

# bits 28-31 are the 4 data bits. Other bits are unused