Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PIC 1 6 C Input and Output RS 2 3 2 serial data Serial LCDIf an electronic gadget has a small alphanumeric LCD, the chances
PIC C Input and Output RS serial data Serial LCDIf an electronic gadget has a small alphanumeric LCD, the chances are that it is a microcontrollerapplication. The LCD used here has a standard serial interface, and only one signal connection isneeded. The signal format is RS a simple lowspeed protocol that allows byte or charactercode to be sent at a time. The data sequence also includes start and stop bits, and simple errorchecking can be applied if required. The PIC FX in common with many microcontrollers, hasa hardware RS port built in Further details of RS are found elsewhere in this book.IntroductionWhat is an LCD?A Liquid Crystal Displays LCD is a thin, flat display device made up of any number ofcolor or monochrome pixels arrayed in front of a light source or reflector. It is oftenutilized in batterypowered electronic devices because it uses very small amounts ofelectric power.LCDs have the ability to display numbers, letters, words and a variety of symbols. Thisexperiment teaches you about LCDs which are based upon the Hitachi HDcontroller chipset. LCDs come in different shapes and sizes with and characters as standard in and line versions. However, all LCDs regardless of theirexternal shape are internally built as a x format. SeeSerial LCDCCS C provides an RS driver routine that works with any IO pin that is the hardware portneed not be used This is possible because the process for generating the RS data frame is nottoo complex and can be completed fast enough to generate the signal in real time. At the standardrate of baud, each bit is about s long, giving an overall frame time of about ms Thedata can be an bit integer or more often, a bit ASCII character codeIn this example, the LCD receives character codes for a row character display. The programuses library routines to generate the RS output, which are called up by the directive # useRS The baud rate must be specified and the send TX and receive RX pins specified asarguments of this directive. The directive must be preceded by a # use delay, which specifies theclock rate in the target system.The LCD has its own controller, which is compatible with the Hitachi MCU, the standard forthis interface. When the system is started, the LCD takes some time to initialize itself; its own MCUneeds time to get ready to receive data. A delay of about ms should be allowed in the maincontroller before attempting to access the LCD. A basic program for driving the LCD is shown inListing below.Table : Essential control Codes for Series X LCDCharacters are sent using the function call putccode whose argument is the ASCII code for thecharacter; the ASCII table given in Table lists the available codes.LCD IOMost LCD modules conform to a standard interface specification. A pin accessis provided having eight data lines, three control lines and three power lines asshown below. Some LCD modules have pins where the two additional pins aretypically used for backlight purposesNote: This image mightdiffer from the actual LCDmodule, the order can befrom left to right or viceversa therefore youshould pay attention, pin is marked to avoidconfusion printed on oneof the pinsPowering up the LCDrequires connectingthree lines: one for theCodes Effect Switch to control modeFollowed by Home to start of row Clear screen Go to start of row Figure : LCD pinoutpositive power Vddusually V one fornegative power orground Vss The Vee pin is usually connected to a potentiometer which is usedto vary the contrast ofthe LCD display. We willconnect this pin to theGND.As you can see from the figure, the LCD connects to the microcontroller throughthree control lines: RS RW and E and through eight data lines DDWith pin LCDs you can use the L and L pins to turn the backlight BL onoffFigure : LCD pinout detailsWhen powered up the LCD display should show a series of dark squares. Thesecells are actually in their off state. When power is applied, the LCD is reset;therefore we should issue a command to set it on Moreover, you should issuesome commands which configure the LCD. See the table which lists all possibleconfigurations below in the code and the explanation to each fieldSending CommandsData to the LCDUsing an LCD is a simple procedure once you learn it Simply put you will place a valueon the LCD lines DDthis value might be an ASCII value character to bedisplayed or another hexadecimal value corresponding to a certain command Sohow will the LCD differentiate if this value on DD is corresponding to data orcommand?Observe the figure below, as you might see the only difference is in the RS signalRegister Select this is the only way for the LCD controller to know whether it isdealing with a character or a command!Figure : Necessary control signalsfor DataCommands Setting the necessary control signals insoftware:For this experiment assume that RS Register Select is connected to PORTA RWReadWrite to PORTAIn this lab experiment we are only writing to the LCD,reading from the LCD is left to the student as home studyand EEnable isconnected to PORTA Moreover, assume that the LCD lines DD are directlyconnected to PORTD.we will introduce two subroutines; one will set the necessary control signals forsending a character sendchar the other for sending a command sendcmdsendcharmovwfbsfbsfnopbcfbcfcallreturnPORTDPORTA,PORTA, PORTA, PORTA, delaysendcmdmovwfbcfbsfnopbcfbcfcallreturnPORTDPORTA, PORTA, PORTA, PORTA,delaySteps to send character to LCD Place the ASCII character on the DD lines Register Select RS to send characters "Enable" Pulse Set High Delay Set Low Delay to give LCD the time needed todisplay the characterSteps to send a command to LCD Place the command on the DD lines Register Select RS to send commands "Enable" Pulse Set High Delay Set Low Delay to give LCD the time needed to carryout the commandTable : Sending CharactersCommands StepsListing Serial LCD Operation LCD.C Serial LCD test send character using putc and printf#include FXh #use delayclock #use rsbaud xmit PIND rcv PIND Define speed and pinsvoid mainchar acap A ; Test datadelayms; Wait for LCD to wake upputc; putc; Home cursordelayms; Wait for LCD to finishwhileputcacap; Send test characterputc; putc; delayms; Move to second rowprintf ASCII c CHAR d acap,acap; Send test data againwhile;Note that the codes for to are x to x so conversion between the code and thecorresponding number is simple. Characters for display can be defined as A to Z and so on insingle quotes, in the program.The character is then replaced by its code by the compiler. The display also needs control codes,for example, to clear the display and reset the cursor to the start position after characters havebeen printed. These are quoted as an integer decimal and sent as binary. Each control code mustbe preceded by the code to distinguish it from data. The code to start the second lineof the display is The display reverts automatically to data mode after any control code. Abasic set of control codes is identified in Table In the example program LCD.C the sample character acap is upper case A ASCII code If a string of fixed characters are to be displayed, the form printf sample text"can be used. The meaning of the function name is print formatted. We often need to insert avariable value within fixed text; in this case, a format code is placed within the display text, andthe compiler replaces it with the value of the variable, which is quoted at the end of the printfstatement. The code d means display the variable value as an integer decimal number, c meansdisplay the ASCII character corresponding to the number. Multiple values can be inserted in order,as seen in program LCD.C A summary of formatting codes is shown in Table Listing shows the program FLOAT.C which illustrates how different variable types aredisplayed, as well as showing the range of each type. Each variable type is output in turn to thedisplay.The general form of the format code is int, where n is the number of significant figures to bedisplayed and t is the output variable type. The number of decimal places printed can also bespecified for floating point numbers.Listing Formatted Variable Output to a Serial Display FLOAT.C MPB Displays variable types and ranges#include FXh#use delayclock #use rsbaud xmit PIND rcv PINDint minbit maxbit ;signed int minbyte maxbyte ;signed int minword maxword ;signed int minlong maxlong ;float testnum ;void maindelayms; Wait for LCD to wakeputc; putc; Home cursordelayms; Wait for LCD to dowhileprintf Bit:d or d minbit, maxbit; delayms;putc; putc; delayms;printf Byte d to d minbyte, maxbyte; delayms;putc; putc; delayms;printf Word Ld minword; putc; putc;delayms; printf to Ld maxword; delayms;putc; putc; delayms;printf Long Ld minlong; putc; putc;delayms; printf to Ldmaxlong; delayms;putc; putc; delayms;printf Float g testnum; putc; putc;delayms; printf or e testnum; delayms;putc; putc; delayms;ACTIVITY Check that it codes for this exercise works correctly. Modify the program so that the LCD outputflashes. Run the applications in MPLAB with Proteus VSM selected as the debug tool. Display theanimated schematic in VSM viewer, with the application COF file attached to the MCU.ACTIVITY Display the code on the first upper row of the LCD the English letters in alphabetical order.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started