Vous êtes sur la page 1sur 15

DIGITAL SYSTEM 2

UNIVERSITY AUTOMOMA OF QUERETARO ENGINEERING FACULTY

Career: Automation Engineering Subject: Digital System II

Practice 7: RS-232 INTERFACE

student: Dublan Barragn Brenda Santa. Lab teachers Name: M. en C. Manuel Toledano Ayala

November 22,2010

DIGITAL SYSTEM 2

Subject:

DIGITAL SYSTEMS 2
GRAPHIC LCD & INTERRUPTIONS 7
Length (Hours)

Practice name
Practice number OBJECTIVE (Learning result)

The student will establish communication to send/receive data from a Computer using RS232 Interface.

THEORETICAL FRAMEWORK - Explain how does the Max232 function The MAX232 is an IC originally designed by a company called Maxim IC that converts signals + /-12V RS232 0/5V signals for the PIC can understand.Voltage increases the pic of + /-12V required by the protocol RS232 to a computer can understand the pic and vice versa. To make the pic sent to a computer serial characters need to send these signals through the MAX232 circuit, so that the computer receives signals from 232 to + /-12V.

DIGITAL SYSTEM 2

This IC MAX232 uses three 0.1 uF capacitors (C5, C6, C7) for function as a voltage multiplier. The fourth (C8) is what known as "bypass capacitor. Since the MAX232 integrated switches number of signals (from / - 12V to 0/5V) uses pulses of current. Because you need these current pulses in bursts, it can disturb your 5V supply. The capacitor of 0.1 uF C8 helps to "decouple" or remove the negative effect of this integrated (switching loads to and from) from your diet. This capacitor bypass should be located close to the VCC and GND pins of the IC. This configuration helps reduce noise in your power supply.

A bypass capacitor is intended to provide a quick burst of energy when food is not enough, is like a UPS system for your integrity. The more distant the decoupling capacitor of the IC, the lower its ability to provide this burst of energy (long cords have some inherent capacitance). It is good engineering practice to always have at least one 0.1 uF capacitor near any CI. Place them an inch pins VCC and GND is right. JP2 is a DB9, DB9 connector is called because it contains 9-pin and is used universally for serial connections. You'll need a male to female serial cable to connect the DB9 of your breadboard to your computer. The "male" end of the cable has metal pins, the end of "female" has the plastic black or blue you receive the pins. If you look closely at a real DB9 connector, you'll see some small numbers near the ports. Pic sent to MAX232 5V signals. The MAX232 going to convert those signals to signals 5V RS232 / - 12V that the computer can understand through the DB9 port that has the back of the case.

DIGITAL SYSTEM 2

- What is a UART and which is the difference with a USART USART stands for "Universal Synchronous / Asynchronous Receiver-Transmitter. It is a device used to transmit or receive sequence data synchronously or asynchronously. The UART only supports asynchronous mode. Connections to the serial ports:

Asynchronous mode: Each byte is treated separately. Sent 1 or 2 bits (bits start) indicating that soon will send a byte of information, eventually send a bit (stop bit). Synchronous mode: bytes are sent per block. Ships inicio.Este special format is faster but needs more software.

DIGITAL SYSTEM 2

- Define the concepts: Baud, Baud rate, Stop bit, Parity

The main settings are 9600bps, 8-N-1. This means that the micro and the PC agreed to speak at 9600 bits per second (bps) and each byte will have 8 data bits, no parity bit, and with one stop bit. This 8-N-1 is fairly common and bsico.Infrmate on parity, stop bit 1.5 and 5 bits of data. Baud Rate: For each cycle of change of level is a binary data. Examples: 110, 300.1200, 2400, 9600, 19.2 kbauds Parity: Method for detecting errors using a bit after the fact but before the stop (stop). Parity (even): the number of bit 1 (including the parity bit) should be par.Paridad odd (odd) bit number to 1 (including the parity bit) must be odd. Data size: 7 or 8 bits per word. 7 bits generating 128 different characters and 8-bit generate 256 characters. Speed transmission / reception (baud): Number of bits that are received or transmitenpor each unit of time.

DIGITAL SYSTEM 2

MATERIALS AND EQUIPEMENT

METHODOLOGY 1.- Write down the program com_serial.c as shown in class. #include <16f877A.h> #include <string.h> #fuses XT,NOPROTECT,NOWDT #use delay(clock=4000000) #use rs232(rcv=PIN_C7,xmit=PIN_C6,baud=9600,bits=8,parity=N) #include <lcd.c> #define buf_length 32 int buf[buf_length],str[buf_length],str_flag=0,i=0,j=0; int On[4]={'O','n',0x0d,0}; int Off[5]={'O','f','f',0x0d,0}; #int_rda void rcv_data() / / Enters the break every time you write a character { buf[i]=getchar(); if(buf[i]==0x0d) { str_flag=1; buf[i+1]=0; strcopy(str,buf); i=0; } else i++; }

void get_string() { regresa: if(str_flag==0) { goto regresa; } str_flag=0; }

DIGITAL SYSTEM 2

void main() { enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); setup_adc(ADC_OFF); setup_adc_ports(NO_ANALOGS); lcd_init(); printf("SOMOS INGENIERIA"); printf(lcd_putc,"Esperando..."); while(TRUE) { #asm NOP #endasm get_string(); lcd_putc("\f"); printf(lcd_putc,"%s",str); if(strcmp(On,str)==0) { output_d(0xFF); } else if(strcmp(Off,str)==0) { output_d(0x00); } } } 2.- Identify and verify that the code has the following lines: a) #use rs232(rcv=PIN_C7,xmit=PIN_C6,baud=9600,bits=8,parity=N) b) #int_rda c) printf("SOMOS INGENIERIA"); d) get_string(); e) enable_interrupts(INT_RDA); f) #include<string.h>

3.- Compile the code 4.- Wire the connections of the MAX232 and LCD to the PIC18F4550 in the protoboard. 5.- Configure the hyperterminal with the values: 9600 bps, 8 data bits, no parity, no flux control and no stop bit. 6.- Program the PIC18F4550. 7.- Plug the serial cable to the PC trough the DB9 connector .

DIGITAL SYSTEM 2 8.- Modify the program com_serial.c to turn on and off the C port when writing the words On <enter> y Off <enter> and show the results on the LCD display. Wire and Write down the results.
#include <18F4550.h> #fuses XT,NOWDT #use delay(clock=4000000) #use rs232(rcv=PIN_C7,xmit=PIN_C6,baud=9600,bits=8,parity=N) #use standard_io(B) #int_RDA void RDA_isr(){ char keypress=' '; keypress=' '; if(kbhit()){ Keypress=getc(); switch (keypress){ case 'P': output_high(PIN_B5); puts("LED On"); break; case 'A': output_low(PIN_B5); puts("LED Off"); break; } } }

void main() { enable_interrupts(Global); enable_interrupts(INT_RDA); puts("BIENVENIDOS"); puts("xxxxxxxxxxxxxxxxxxxxxxxxxxx"); puts("Presione P-prender A-apagar"); for (;;){ } }

DIGITAL SYSTEM 2

DIGITAL SYSTEM 2

9.- Modify the Configuration Word to enable the Watch dog but DO NOT refresh it. Write down the observed. 10.- Modify the program to refresh the Watch dog. Write down the observed. 11.- Modify the program in order to watch 4 Channels of the ADC (by writing CH0,CH1,CH2 and CH3) in the hyperterminal.The ADC must be configured to 10 bits of resolution. 12.- Modify the program to show built a DAC (Digital to analog converter) by using a microcontroller and a filter. This is: When the user types 5V on the hyperterminal, the voltage measured on a load must be 5 Volts, when the user types 3.5 the same and when the user types 1.1 too. In other words, the user will type any value from 0 to 5 volts and the microcontroller must deliver that voltage. (Check point)

10

DIGITAL SYSTEM 2

11

DIGITAL SYSTEM 2

12

DIGITAL SYSTEM 2

PRACTICE EVALUATION QUESTIONARY 1. Explain the fields in the line code: #use rs232(rcv=PIN_C7,xmit=PIN_C6,baud=9600,bits=8,parity=N) in this part of the code sets the communication protocol, which is the way down the rules for communication. assign the following pins: c7 c6 as wide receiver and transmitter, we indicate the baud speed which are units of speed to transmit data, we tell how much data are transmitted which are 8 bits, and tell him to tell us if there was problem communicating that is done by parity. 2. Which is the function of the line #int_rda? Enters the break every time you write a character 3. What does de function get_string( ) do? is the function that sends a call while you type a character and tells when they finish writing, by str_flag 4. Why is included as header file the library string.h? that is going to be manipulated with strings

5. Add the code to this report commenting variables, functions, structures and processes. Codice: #include <18f4550.h> #device ADC=10 #include <stdlib.h> #include <string.h> #fuses XT,NOPROTECT,NOWDT 13

DIGITAL SYSTEM 2 #use delay(clock=4000000) #use rs232(rcv=PIN_C7,xmit=PIN_C6,baud=9600,bits=8,parity=N, stream=PORT1) #include <lcd.c> #define buf_length 32// is the buffer length

int buf[buf_length],str[buf_length];// is the same size of the buffer because we use that for work int str_flag=0, i=0,n=0,voltaje;

#int_rda void rcv_data() //this interruption in went we write a character { n++; buf[i]=getchar(); if(buf[i]==0x0d) { str_flag=1; buf[i+1]=0; strcopy(str,buf); str[i]=0; i=0; } else i++; }

void get_string()// we use that while we write the word { regresa: //etiqueta "regresa" if(str_flag==0) { goto regresa; //se va a la etiqueta "regresa" } str_flag=0; } void main() { float voltage; enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); setup_adc(ADC_OFF); setup_adc_ports(NO_ANALOGS); setup_ccp1(CCP_PWM); setup_timer_2(T2_DIV_BY_1,100,1); puts("BIENVENIDOS"); puts("RS232");

14

DIGITAL SYSTEM 2

lcd_init(); printf(lcd_putc,"Esperando..."); lcd_gotoxy(1,0); printf(lcd_putc,"RS232"); while(TRUE) { get_string(); voltage= atof (str); voltage = voltage *20; lcd_putc("\f"); voltaje=(int) voltage; printf(lcd_putc,"V=:%s DUTY:=%i",str,voltaje); set_pwm1_duty(voltaje); delay_ms(1500); } } Conclusions In this practice I learned that there are many ways to communicate with the computer for communication protocols that we need to help us to be in sync with it and be able to understand one device to another as in this case was the pic with the PC, the communication serial communication was used because it has advantages such as: * Used for transmission over long distances * It requires fewer cables (fewer lines of data) * slower, but results in fewer errors due to noise. for this communication which need the max232 and explain its functionality. I am happy to finally understand the serial communication.

Bibliography http://focus.ti.com/lit/ds/symlink/max232.pdf http://www.zator.com/Hardware/H2_5_1_1.htm http://www.maicas.net/goofy/capc.htm

15

Vous aimerez peut-être aussi