P. 1
Lab12

Lab12

|Views: 0|Likes:
Published by Ammar Naveed Bajwa
Embeddid System 12
Embeddid System 12

More info:

Categories:Types, Research
Published by: Ammar Naveed Bajwa on Jun 04, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less

06/04/2013

pdf

text

original

Embedded Systems – IE403

Lab Work

Lab #12

Objective
To perform serial communication between two microcontrollers

Theory
Serial communication is often used either to control or to receive data from an embedded microprocessor. Serial communication is a form of I/O in which the bits of a byte begin transferred appear one after the other in a timed sequence on a single wire. Serial communication has become the standard for intercomputer communication. As shown in figure 12.1, each byte is preceded by a start bit and followed by one stop bit. The start and stop bits are used to synchronize the serial recivers. The data byte is always transmitted least-significantbit first. For error checking it is possible to include a parity bit as well, just prior to the stop bit. The bits are transmitted at specific time intervals determined by the baud rate of the serial signal. The baud rate is the reciprocal of the time to send 1 bit. Error-free serial communication requires that the baud rate, number of data bits, number of stop bits, and presence or absence of a parity bit be the same at the transmitter and at the receiver.

Figure 12.1: Data being transmitted serially

8051 provides a transmit channel and a receive channel of serial communication. The transmit data pin (TXD) is specified at P3.1, and the receive data pin (RXD) is at P3.0. The serial signals provided on these pins are TTL signal levels and must be boosted and inverted through a suitable converter(MAX232) to comply with RS232 standard if we want to communicate with the PC. All modes are controlled through SCON, the Serial CONtrol register. The SCON bits are defined as SM0, SM1, SM2, REN, TB8, RB8, TI, RI from MSB to LSB. The timers are controlled using TMOD, the Timer MODe register, and TCON, the Timer CONtrol register. The hardware connections are simple as shown in the figure 12.2

Figure 12.2: Hardware Connections for serially interfacing two microcontrollers

Group Members:

Ali Asad (1936)

Safdar Abbasi (1926)

3: Flow Chart for serial communication between two controllers Group Members: Ali Asad (1936) Safdar Abbasi (1926) .Embedded Systems – IE403 Lab Work Lab #12 Flow Chart Serial Receive ISR Serial Transmit ISR START Initialize Serial Communication Display this data on 7-seg Clear TI flag Wait for user input by keypad Clear RI flag Return Prepare to transmit this data Return END Figure 12.

@A+DPTR .Encode data to 7-segment 0184 F599 24 MOV SBUF. REN enabled 017C 75A890 19 MOV IE.encode data to 7-segment 018F F5A0 32 MOV P2.get hex code from keypad 0183 93 23 MOVC A.0xF9.enable serial interrupt only 017F D28E 20 SETB TR1 .#0FDH .SBUF .transmit this data serially 0186 80F9 25 SJMP FOREVER .it also displays data on 7-seg received from other SOURCE .TRANS .0x92.Embedded Systems – IE403 Lab Work Lab #12 Source Code LOC OBJ LINE 1 2 communication 3 microcontroller 4 5 ORG 0000H 6 LJMP MAIN 7 0023 8 ORG 0023H 0023 020188 9 LJMP SERIAL 10 0160 11 ORG 0160H .0xA4.#50H .0xF8.MOVC A.0x83.#20H .input hex code from keypad with debouncing 0000 0000 020170 .7-Seg.Common-Anode/Cathode Choice 0173 758920 16 MOV TMOD.0xA1.0xB0.A .otherwise due to receive 31 . Common Anode code for digits 0 to 9 and letters A to F 0160 C0F9A4B0 12 CA: DB 0xC0.#90H .save A 018D E599 30 MOV A.clear RI since CPU does not 0195 32 35 RETI .send this 7-segment at port2 0191 D0E0 33 POP ACC .return from ISR 0196 36 TRANS: 0196 C299 37 CLR TI 0198 32 38 RETI 39 40 41 .0x8E 0164 999282F8 0168 80908883 016C C6A1868E 13 0170 14 MAIN: 0170 900160 15 MOV DPTR.and sends it to another microcontroller using serial Group Members: Ali Asad (1936) Safdar Abbasi (1926) .0x88.8-bit.0x82.IN_HEX .A .0x86.timer 1.repeat this forever 26 0188 27 SERIAL: 0188 20990B 28 JB TI.This program reads data from a hex keypad .0x80.ready serial communication 0181 21 FOREVER: 0181 3199 22 CALL IN_HEX .0x90.9600 baud-rate 0179 759850 18 MOV SCON.restore A 0193 C298 34 CLR RI . 1 stop.0xC6.0x99.@A+DPTR .#CA . mode-2(autoreload) 0176 758DFD 17 MOV TH1.jump if TI is high 018B C0E0 29 PUSH ACC .

repeat until all rows checked Accumulator if pressed 01AE 62 01AE 74FE 63 01B0 7E04 64 01B2 65 01B2 F590 66 01B4 FF 67 01B5 E590 68 01B7 54F0 69 01B9 B4F007 70 01BC EF 71 01BD 23 72 01BE DEF2 73 01C0 C3 74 01C1 8015 75 01C3 76 01C3 FF 77 01C4 7404 78 01C6 C3 79 01C7 9E 80 01C8 FE 81 01C9 EF 82 01CA C4 83 01CB 7D04 84 01CD 85 01CD 13 86 01CE 5006 87 01D0 0E 88 01D1 0E 89 01D2 0E 90 01D3 0E 91 01D4 DDF7 92 Group Members: Ali Asad (1936) Safdar Abbasi (1926) .P1 .R6 MOV R6.A .#0FEH .A .ground next column DJNZ R6. .put this in low nibble MOV R5.R7 .#1 .#4 .key pressed? JNC IN_HEX .read back port ANL A.no: repeat 50 POP ACC .no: check again DJNZ R3.key pressed? JC BACK2 .GET_KEY .#4 .use R5 as counter AGAIN: RRC A . .R6 .save hex code BACK2: MOV R3.activate (ground) current column MOV R7.return .yes: repeat 50 times PUSH ACC .any row active? MOV A.A .save in R7 MOV A.holds the hexcode of pressed key DJNZ R5.R7 .wait for key release BACK3: CALL GET_KEY .R6 finally INC R6 .returns C = 0 if no key is pressed .isolate rows by masking columns CJNE A.AGAIN .#0F0H.get keypad status .start with column 0 by grounding it MOV R6.#1 .no key pressed SJMP EXIT .TEST CLR C .returns C = 1 and hex code in GET_KEY: MOV A.recover hex code RET .restore rows scan result SWAP A .rotate-right in carry JNC DONE .prepare to calculate column CLR C .no: move to RL A .Embedded Systems – IE403 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 Lab Work Lab #12 0199 0199 019B 019B 019D 019F 01A1 01A3 01A3 01A5 01A5 01A7 01A9 01AB 01AD 7B01 31AE 50FA DBFA C0E0 7B01 31AE 40FA DBFA D0E0 22 .debounce count BACK: CALL GET_KEY .done when C = 0 INC R6 .use R6 as column counter TEST: MOV P1.BACK3 .A .yes: keep checking DJNZ R3.add 4 INC R6 .clear carry flag SUBB A.save ACC (accumulator) MOV A.return with C = 0 KEY_HIT: MOV R7.for key press and key release (50 repeats for each) IN_HEX: MOV R3.#0F0H .until the row is detected INC R6 .BACK .save result in R6 MOV A.column number = 4 .#4 .KEY_HIT .

R6 EXIT: RET END Lab #12 .1: ASM listing for serial communication between two controllers Group Members: Ali Asad (1936) Safdar Abbasi (1926) .save key hex code in A Code 12.C = 1 (key press confirmed!) .Embedded Systems – IE403 01D6 01D6 D3 01D7 EE 01D8 01D8 22 93 94 95 96 97 98 Lab Work DONE: SETB C MOV A.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->