Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need to write a report on below, it must include aim, procedure, discuss and comparison and conclusion:PIC 1 6 C Input and Output RS 2

Need to write a report on below, it must include aim, procedure, discuss and comparison and conclusion:PIC16 C Input and Output RS232 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 RS232, a simple low-speed protocol that allows 1 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 16F62X, in common with many microcontrollers, hasa hardware RS232 port built in. Further details of RS232 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 battery-powered 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 HD44780controller chipset. LCDs come in different shapes and sizes with 8,16,20,24,32, and 40characters as standard in 1,2 and 4line versions. However, all LCDs regardless of theirexternal shape are internally built as a 40x2 format. SeeSerial LCDCCS C provides an RS232 driver routine that works with any I/O pin (that is, the hardware portneed not be used). This is possible because the process for generating the RS232 data frame is nottoo complex and can be completed fast enough to generate the signal in real time. At the standardrate of 9600 baud, each bit is about 100 s long, giving an overall frame time of about 1 ms. Thedata can be an 8-bit integer or, more often, a 7-bit ASCII character code.37In this example, the LCD receives character codes for a 2-row -16-character display. The programuses library routines to generate the RS232 output, which are called up by the directive # useRS232. 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 44780 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 500 ms should be allowed in the maincontroller before attempting to access the LCD. A basic program for driving the LCD is shown inListing 4.1 below.Table 1: Essential control Codes for Series 2X16 LCDCharacters are sent using the function call putc(code), whose argument is the ASCII code for thecharacter; the ASCII table given in Table 2. lists the available codes.LCD I/OMost LCD modules conform to a standard interface specification. A 14-pin accessis provided having eight data lines, three control lines and three power lines asshown below. Some LCD modules have 16 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, pin1 is marked to avoidconfusion (printed on oneof the pins).Powering up the LCDrequires connectingthree lines: one for theCodes Effect254 Switch to control modeFollowed by00 Home to start of row 101 Clear screen192 Go to start of row 2Figure 4: LCD pin-out38positive power Vdd(usually +5V), 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 D0-D7.With 16-pin LCDs, you can use the L+ and L- pins to turn the backlight (BL) on/off.Figure 5: LCD pin-out 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 field)Sending Commands/Data to the LCDUsing an LCD is a simple procedure once you learn it. Simply put you will place a valueon the LCD lines D0-D7(this value might be an ASCII value (character to bedisplayed), or another hexadecimal value corresponding to a certain command). So39how will the LCD differentiate if this value on D0-D7 is corresponding to data orcommand?Observe the figure below, as you might see the only difference is in the RS signal(Register Select), this is the only way for the LCD controller to know whether it isdealing with a character or a command!Figure 7: Necessary control signalsfor Data/Commands Setting the necessary control signals insoftware:For this experiment assume that RS (Register Select) is connected to PORTA1, R/W(Read/Write) to PORTA2(In this lab experiment we are only writing to the LCD,reading from the LCD is left to the student as home study)and E(Enable) isconnected to PORTA3. Moreover, assume that the LCD lines D0-D7 are directlyconnected to PORTD.we will introduce two subroutines; one will set the necessary control signals forsending a character (send_char), the other for sending a command (send_cmd).1send_charmovwfbsfbsfnopbcfbcfcallreturnPORTDPORTA,1PORTA, 3PORTA, 3PORTA, 2delay1send_cmdmovwfbcfbsfnopbcfbcfcallreturnPORTDPORTA, 1PORTA, 3PORTA, 3PORTA,2delay223333334440Steps to send character to LCD1. Place the ASCII character on the D0-D7 lines2. Register Select (RS)=1 to send characters3. "Enable" Pulse (Set High Delay Set Low)4. Delay to give LCD the time needed todisplay the characterSteps to send a command to LCD1. Place the command on the D0-D7 lines2. Register Select (RS)=0 to send commands3. "Enable" Pulse (Set High Delay Set Low)4. Delay to give LCD the time needed to carryout the commandTable 2: Sending Characters/Commands StepsListing 4.1 Serial LCD Operation// LCD.C// Serial LCD test - send character using putc() and printf()///////////////////////////////////////////////////////////////#include "16F62X.h "#use delay(clock =4000000)#use rs232(baud =9600, xmit = PIN_D0, rcv = PIN_D1)// Define speed and pinsvoid main(){char acap =' A ' ; // Test datadelay_ms(1000); // Wait for LCD to wake upputc(254); putc(1); // Home cursordelay_ms(10); // Wait for LCD to finishwhile(1){putc(acap); // Send test characterputc(254); putc(192); delay_ms(10); // Move to second rowprintf(" ASCII %c CHAR %d ",acap,acap); // Send test data againwhile(1);}}41Note that the codes for 0 to 9 are 0 x 30 to 0 x 39, 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 254(11111110) to distinguish it from data. The code to start the second lineof the display is 192. The display reverts automatically to data mode after any control code. Abasic set of control codes is identified in Table 1.In the example program LCD.C, the sample character acap is upper case A, ASCII code_1000001_6510. 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 3.42Listing 4.2 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 4.2. Formatted Variable Output to a Serial Display/* FLOAT.C MPB 4_3_07 Displays variable types and ranges****************************************************/#include "16F62X.h"#use delay(clock =4000000)#use rs232(baud =9600, xmit = PIN_D0, rcv = PIN_D1)int1 minbit =0, maxbit =1;signed int8 minbyte =-127, maxbyte =127;signed int16 minword =-32767, maxword =32767;signed int32 minlong =-2147483647, maxlong =2147483647;float testnum =12345.6789;void main(){delay_ms(1000); // Wait for LCD to wakeputc(254); putc(1); // Home cursordelay_ms(10); // Wait for LCD to dowhile(1){printf(" Bit:%d or %d ",minbit, maxbit); delay_ms(1000);putc(254); putc(1); delay_ms(10);printf(" Byte %d to %d ",minbyte, maxbyte); delay_ms(1000);putc(254); putc(1); delay_ms(10);43printf(" Word %Ld ",minword); putc(254); putc(192);delay_ms(10); printf(" to %Ld ",maxword); delay_ms(1000);putc(254); putc(1); delay_ms(10);printf(" Long %Ld ",minlong); putc(254); putc(192);delay_ms(10); printf(" to %Ld",maxlong); delay_ms(1000);putc(254); putc(1); delay_ms(10);printf(" Float %5.4g ",testnum); putc(254); putc(192);delay_ms(10); printf(" or %e ", testnum); delay_ms(1000);putc(254); putc(1); delay_ms(10);}}ACTIVITY 4.1Check 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 4.2Display the code on the first upper row of the LCD the 26 English letters in alphabetical order.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions