RS232 #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7

Slides:



Advertisements
Similar presentations
Analog to digital converter
Advertisements

EUSART Serial Communication.
Electronics Design Lab TUTORIAL PIC Microcontrollers Francesco Tenore 2/10/2006.
Jordan Barry Victor Brzeski
Review: Interrupts & Timers
4-1 Timers Timers can be used for  timing  event counting  pulse width measurement  pulse generation  frequency multiplication There are 8 Timers.
1 Lab2: A/D Converter. 2 This circuit connects a variable voltage to an A/D port on the AVR mcu. Your software running on the AVR mcu will read the digital.
Slides created by: Professor Ian G. Harris Inputs and Outputs PIC Vcc RA3 RA4 RA5  Make an LED toggle state when button is pressed  Need to read RA3,
ECT 357 Ch 10 Analog to Digital COnversion. Today’s Quote: It’s better to die with a good name than to live with a bad one. It’s better to die with a.
Interfacing ADC to 8051.
Railway Foundation Electronic, Electrical and Processor Engineering.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
Railway Foundation Electronic, Electrical and Processor Engineering.
Eejit’s guide to using a LCD alphanumeric display with the CCS C compiler 1.Hardware connection 2.The LCD.C include file 3.An example.
Smart-grid Interface with Photovoltaic Installation – Phase 2 PP-01 Team members: Matt Koresh Ivan Mills Matt Martin Advisor: Dr. Aliprantis.
In this PPT, all the materials covered up for the PIC microcontroller set-up would be studied. Preliminary skills: Knowing of basic C grammar and basic.
Input/Output mechanisms
V 0.91 Polled IO versus Interrupt Driven IO Polled Input/Output (IO) – processor continually checks IO device to see if it is ready for data transfer –Inefficient,
September, 2007ENGR Low-Level Robot Control Mechatronics: Motors, sensors & embedded controls.
16F877A. Timer 0 The Timer0 module timer/counter has the following features: –8-bit timer/counter –Readable and writable –8-bit software programmable.
A Few Words From Dilbert
Introduction to PIC-C. Required Software PIC-C Compiler Firmware Downloader Driver for the USB->Serial Adapter.
Digital to Analogue Converter
Microchip PIC Networks Amrit Bandy, Ben Funk Neil Goldsman.
1 Lab 5: Controls and feedback. 2 Lab 5: Control and Feedback This embedded system uses the Photo sensor to detect the light intensity of the environment.
MICROCONTROLLER SYSTEMS Part 1. Figure 1.1Elements of a digital controller CPU Central Processing Unit Input Peripherals Output Peripherals ROM Read Only.
CCP MODULES  The CCP module (Capture/Compare/PWM) is a peripheral which allows the user to time and control different events.  Capture Mode provides.
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
Introduction to PIC-C. Installing PIC-C Goto Username/pass = guest/cpecmu Download and install:  IDEUTIL  PCWHD.
Teachers Name : Suman Sarker Telecommunication Technology Subject Name : Microcontroller & Embedded System Subject Code : 6871 Semester : 7th Department.
Interrupts Microprocessor and Interfacing
I NTRODUCTION TO PIC PROGRAMMING By : S HERIF H ARHASH.
Analog to Digital Converter (ADC). Analog to Digital Converters  Microcontroller understands only digital language.  To convert the analog output from.
C PERIPHERAL INTERFACES
Lecture 11: Liquid Level Control System: A Case Study 1.
Device Overview 1.  The advantages of all PIC18Fxxxx microcontrollers:  High computational performance  High-endurance  Enhanced Flash program memory.
Department of Electronic & Electrical Engineering Further work? Simple Voltmeter. ● Analogue to Digital converter (MCP3001 SPI ) ● Analogue → 10bit binary.
Arduino Mega Arduino Mega 2560 Arduino Mega 2560.
Components of a typical full-featured microcontroller.
MICROCONTROLLER INTERFACING WITH STEPPER MOTOR MADE BY: Pruthvirajsinh Jadeja ( ) COLLEGE:DIET BRANCH:EC.
Microcontroller basics Embedded systems for mortals.
Electronic instrumentation Digitization of Analog Signal in TD
Criteria for choosing a microcontroller A microcontroller must meet the task at hand efficiency and cost effectively. Speed. What is highest speed of.
1 Lab 4: D/A Converter Lab 4: D/A Converter This is a simple resistive network for a D/A converter Port 1, Port 0 are digital inputs ==> 00 (minimum),
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
Microprocessors A practical approach..
FOR MORE CLASSES VISIT   ECET 340 Week 1 HomeWork 1  ECET 340 Week 1 iLab 1  ECET 340 Week 2 HomeWork 2  ECET 340 Week 2 iLab.
1. PIC ADC  PIC18F877 has 8 analog input channels i.e. port A pins(RA0 to RA5) and port E pins(RE1 and RE2). These pins are used as Analog input pins.
CEng3361 CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT Spring 2011 Recitation 06.
 Mini-Computer ◦ Microprocessor  The Brains  Arithmetic Logic Unit (ALU)  Control Unit  Program/ Data Storage  Peripherals (Input/Output)  Low-Cost.
USING TV REMOTE AS A CORDLESS MOUSE FOR THE COMPUTER
CORDLESS MOUSE FEATURES BY TV REMOTE USING PIC MICROCONTROLLER
Application Case Study Christmas Lights Controller
Application Case Study Security Camera Controller
Networking of Multiple street junction signals for better traffic management Submitted by:
Microcontroller basics
Overview Basic PIC Circuits Development in C using CCS
Chapter 13 Linear-Digital ICs
The Arduino Microcontroller: Atmel AVR Atmega 328
ECET 340 Competitive Success/snaptutorial.com
ECET 340 Education for Service-- snaptutorial.com.
ECET 340 Teaching Effectively-- snaptutorial.com.
ECE 354 Computer Systems Lab II
PIC18F458 Analog-to-Digital
ADC and DAC Programming in AVR
ADC and DAC Data Converter
8051 Micro Controller.
Robotics System Lecture 11_12: DC Motor
ADC and DAC Data Converter
PIC Microcontroller ADC interfacing Prof. Ashvini Kulkarni
Presentation transcript:

RS232 #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7 BAUD=x; Set baud rate to x units bits/sec XMIT=pin ; Set transmit pin RCV=pin; Set receive pin printf("%u",value); the printf command is used to write data to serial port.

RS232 RS232 receive data available, at the receiver pin , for example for PIC16F877 at pin RC7. value = getc(), value = fgetc(stream), value=getch(), value=getchar() This function waits for a character to come in over the RS232 RCV pin and returns the character.

Example This example receives data and resends it via RS232

Continue ADC The A/D converter module has the following features: The converter generates a 10-bit binary result (or 8-bit) using the method of successive approximation and stores the conversion results into the ADC registers (ADRESL and ADRESH); The A/D converter converts an analog input signal into a 10-bit binary number (or 8-bit); The minimum resolution or quality of conversion may be adjusted to various needs by selecting voltage references Vref- and Vref+.

Continue ADC

To select the Vref- and Vref+: Choose Constants used in SETUP_ADC_PORTS(): Example: (AN0_VREF_VREF) // A0 VRefh=A3 VRefl=A2 (AN0_AN1_AN2_AN4_VSS_VREF)// A0 A1 A2 A5 VRefh=A3

Continue ADC To select the number of bits which read_adc() returns use: #Device ADC=10 ADC=x Where x is the number of bits read_adc() should return If we use PIC16f877 x could be 8 or 10 Bits.

Interrupts Three simple steps: First: Enable Interrupts Global: enable_interrupts(GLOBAL);//tells the PIC that we are going to use interrupt Second: Enable the Specific type of Interrupt you want to use: enable_interrupts(INT_xxx);//specify the type of interrupt. See the devices .h file for all valid interrupts for the part

Interrupts Third: Write the Interrupt Subroutine: This function is executed when the interrupt occurs. The subroutine is written outside the Main loop. The function should be written directly after #Int_xxx The name of subroutine should refer to the action taken.

#Int_xxx These directives specify the following function is an interrupt function. #INT_EXT //External interrupt #INT_RB //Port B any change on B4-B7

Example Using INT_RB The following example shows how to use INT_RB. The Microcontroller is reading analog signal from analog channel one, but if a change occurred at pin RB4 (Low to High or High to Low) an Interrupt occurs and the microcontroller is programmed to light a LED at Pin RB2 and a Motor is on at pins RB0, RB1.

Practically Don't forget to connect the oscillator and power. Note: Practically the motor is not simply connected as shown. (it needs a driver circuit between MC and the motor it self). Practically Don't forget to connect the oscillator and power.

#include <16f877.h> #fuses hs,nowdt #use delay (clock=20000000) #use rs232 (baud=9600,xmit=pin_c6,rcv=pin_c7) #int_Rb //Interrupt Subroutine (Motor on Clock Wise and LED On/Off five times) Rb_isr() { int i; output_high(pin_b0); output_low(pin_b1); for ( i=1;i<=5;i++) {output_high(pin_b2); delay_ms(500); output_low(pin_b2); delay_ms(500);} output_low(pin_b0); output_low(pin_b1);}

Cont. code void main() {int value; enable_interrupts(INT_Rb); enable_interrupts(GLOBAL); setup_adc( ADC_CLOCK_INTERNAL ); setup_adc_ports( ALL_ANALOG ); while (1) { set_adc_channel(1); value= read_adc(); printf("A/D value = %u\n\r",value);}}

Other Interrupts INT_EXT //External interrupt INT_RDA //RS232 receive data available INT_TIMERx //Timer x overflow

INT_EXT Change at pin RB0 Also requires specifying the edge change using: EXT_INT_EDGE( ) Determines when the external interrupt is acted upon. The edge may be L_TO_H or H_TO_L to specify the rising or falling edge Example: ext_int_edge( H_TO_L ); // Sets up EXT This is written after enabling the interrupts (In the main loop)

INT_RDA Rather than waiting serial data to be received from the Rx pin, give this job to a specialist which is INT_RDA. If data is available at the receiver pin an Interrupt occurs.

Example The First PIC transmit data to be received by the second PIC. see the figure next slide. Receive the data using Interrupt RDA.

Transmitter Code #include <16f877a.h> #fuses xt,nowdt #use delay(clock=4000000) #users232(baud=9600,xmit=pin_c6,rcv=pin_c7) void main(){ while(1){ printf("HIJJAWI "); delay_ms(500); }}

Receiver Code #include<16f877a.h> #fuses xt,nowdt #use delay(clock=4000000) #include<lcd.c> #use rs232(baud=9600,xmit=PIN_c6,rcv=PIN_c7) char Rx[50]; int i=0; #int_RDA RDA_isr() {Rx[i++]=getch();} void main() {enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); lcd_init(); while(1) {lcd_putc('\f'); lcd_gotoxy(1,1); printf(lcd_putc,"%s",Rx);}}

INT_TIMERx To deal with timers you must know the following simple commands: value=get_timer0() //Returns the count value of a real time clock/counter. RTCC and Timer0 are the same. All timers count up. When a timer reaches the maximum value it will flip over to 0 and continue counting (254, 255, 0, 1, 2...). set_timer0(value)// Sets the count value of a real time clock/counter.

INT_TIMERx // 20 mhz clock, no prescaler, set timer 0 // to overflow in 35us set_timer0(81);     // 256-(.000035/(4/20000000))