SlideShare uma empresa Scribd logo
1 de 34
Chapter 5 PIC Interfacing
[object Object],[object Object],[object Object],Analog to digital conversion
Analog to digital conversion (cont..) ,[object Object],[object Object],[object Object],[object Object],[object Object]
Analog to digital conversion (cont..) ,[object Object], C X Thermistor 22k 5 V 0 V
Analog to digital conversion (cont..) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Analog to digital conversion (cont..) ,[object Object]
Analog to digital conversion (cont..) 16C7X device specifications
Analog to digital conversion (cont..) ,[object Object],[object Object],[object Object]
Analog to digital conversion (cont..) Memory map of PIC 16C711 BANK0 BANK1
[object Object],[object Object],[object Object],[object Object],Analog to digital conversion (cont..)
Analog to digital conversion (cont..) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Analog to digital conversion (cont..) ,[object Object],[object Object],[object Object],[object Object]
Analog to digital conversion (cont..) ADCON0 register ADCS1 ADCS0 - CHS1 CHS0 GO/DONE - ADON Bit 7 Bit 0 1 = A/D on 2 = A/D off 1 = A/D in progress 0 = A/D finished Analog channel select 00 = channel 0, AN0 01 = channel 1, AN1 10 = channel 2, AN2 11 = channel 3, AN3
Analog to digital conversion (cont..) ,[object Object],[object Object],[object Object],[object Object]
Analog to digital conversion (cont..) Bit 7 Bit 0 A/D Port Configuration bits ADCON1 Register ADCON1 Port configuration - - - - -  - PCFG1 PCFG0 Vdd D D D D 11 Vdd D D A A 10 A3 Vref A A A 01 Vdd A A A A 00 Ref A3 A2 A1 A0 PCFG
[object Object],Analog to digital conversion (cont..) bsf ADCON0, ADON ;A/D converter is on bsf ADCON0, GO ;Start A/D conversion ADLoop btfsc ADCON0, GO ;has conversion finished? goto ADLoop ;no, so keep looping etc…. ;yes, so exits loop
Analog to digital conversion (cont..) ,[object Object]
Serial Communication ,[object Object]
Serial Communication (cont..) ,[object Object],[object Object],[object Object],[object Object]
Serial Communication (cont..) Pin designations on RS232 connector (Ring Indicator) 9. RI (Clear To Send) 8. CTS (Request To Send) 7. RTS (Data Set Ready) 6. DSR (Ground) 5. GND (Data terminal Ready) 4. DTR (Transmit Data) 3. TXD (Receive Data) 2. RXD (Carrier Detect) 1. CD
Serial Communication (cont..) ,[object Object],[object Object],[object Object]
Serial Communication (cont..) Connecting a microcontroller to a PC via a MAX232 line interface chip   Program Example
Serial Communication (cont..) ,[object Object],rs232init   Macro for initializing the pin for transmitting data (TX-pin).    Example:  RS232init  Sendw   Sending ASCII value of data found in W register.  Example:  movlw 't'  call Sendw  rs232text   Sending ASCII value of a specified text  Example:  rs232 “HELLO WORLD"  rs232byte Sending ASCII value of decimal digits of 8-bit variable  Example:  movlw .123 movwf TXdata rs232byte TXdata   ;Send '1', '2', '3'
Serial Communication (cont..) ,[object Object],[object Object],[object Object]
Pulse Width Modulation (PWM) ,[object Object],[object Object],[object Object]
Pulse Width Modulation (PWM) – (Cont..) Figure 1
Pulse Width Modulation (PWM) – (Cont..) list p= 16f84 ;************************************************************* PORTB   EQU   0x06  ; port b equate  duty   EQU   0x0c   ; length of duty cycle  temp  EQU   0x0d   ; length of duty cycle  ;************************************************************* c   EQU   0  ; status bit to check after subtraction   ;*************************************************************  ORG   0x000  The only equate of signifficance here is PWM. This register will be used  to store the length of the PWM signal to be generated.
Pulse Width Modulation (PWM) – (Cont..) The next portion of code contains the actual instructions that tell  the PIC what to do.   start   MOVLW   0x00  ;load W with 0x00 make port B output   TRIS   PORTB   ;copy W tristate to port B outputs   MOVLW   0x00  ;fill w with zeroes   MOVWF   PORTB   ;set port b outputs to low These lines   ;set up port B as outputs.   ;All outputs are then set to low.   rstrt MOVLW   d'0'  MOVWF   PORTB   MOVLW   d'157'  ;Duty cycle length movwf duty   After setting up the ports, the main loop is begun. At the beginning of the main  loop, all port b pins are set to low just incase they are high when they shouldn't  be. The duty cycle is then set to 157 (a 50% duty cycle. 255 corresponds to  100% and 0 corresponds to 0%).
Pulse Width Modulation (PWM) – (Cont..) b0loop   MOVF   duty,w   MOVWF   temp   BSF   PORTB ,0  pwma   NOP   NOP   NOP   NOP  NOP  NOP  NOP  NOP  NOP  NOP NOP  NOP   DECFSZ   temp   GOTO   pwma
Pulse Width Modulation (PWM) – (Cont..) The next bit of code is the loop for the PWM signal generated at pin B0.  The pwm1a loop generates the high portion of the PWM signal. The duty  cycle is stored in temp and then the pin is set high. after a pause,  temp is decremented and so long as it doesnt reach zero the pause is  repeated and temp is decremented again. After temp reaches zero, the  code continues.
Pulse Width Modulation (PWM) – (Cont..) MOVLW   d'255 '  MOVWF   temp   MOVF   duty,w   SUBWF   temp,f   BCF   PORTB ,0  pwmb   NOP  NOP  NOP  NOP  NOP  NOP  NOP  NOP  NOP  NOP  NOP  NOP
Pulse Width Modulation (PWM) – (Cont..) DECFSZ   temp   GOTO   pwmb   GOTO   rstrt END The next portion of code generates the low part of the PWM signal.  The value 255 is stored in temp, and the duty cycle is subtracted from this.  This gives the remaining length of signal to be generated. Temp is then  decremented in the same manner as above, this time with B0 set to low.  Once the entire PWM signal has been generated, the code repeats.  This code causes a PWM signal to be generated with a duty cycle  proportional to the value set. The frequency of the signal can also be  adjusted by varying the delay (the number of nop's used).
Pulse Width Modulation (PWM) – (Cont..) - Application ,[object Object],[object Object],[object Object],[object Object],[object Object]
Pulse Width Modulation (PWM) – (Cont..) - Application ,[object Object],[object Object]

Mais conteúdo relacionado

Mais procurados

Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]
gauravholani
 
Programming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerProgramming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontroller
Corrado Santoro
 
Pic microcontroller step by step your complete guide
Pic microcontroller step by step your complete guidePic microcontroller step by step your complete guide
Pic microcontroller step by step your complete guide
Ashraf Said AlMadhoun - Educational Engineering Team
 

Mais procurados (19)

Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]
 
Programming pic microcontrollers
Programming pic microcontrollersProgramming pic microcontrollers
Programming pic microcontrollers
 
Programming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerProgramming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontroller
 
Microcontroller lec 2
Microcontroller  lec 2Microcontroller  lec 2
Microcontroller lec 2
 
Introduction to MPLAB IDE
Introduction to MPLAB IDEIntroduction to MPLAB IDE
Introduction to MPLAB IDE
 
Analog I/O in PIC16F877A
Analog I/O in PIC16F877AAnalog I/O in PIC16F877A
Analog I/O in PIC16F877A
 
174085193 pic-prgm-manual
174085193 pic-prgm-manual174085193 pic-prgm-manual
174085193 pic-prgm-manual
 
Digital i o
Digital i oDigital i o
Digital i o
 
Getting started with pic microcontrollers
Getting started with pic microcontrollersGetting started with pic microcontrollers
Getting started with pic microcontrollers
 
PIC Microcontrollers
PIC MicrocontrollersPIC Microcontrollers
PIC Microcontrollers
 
Presentation
PresentationPresentation
Presentation
 
Introduction to pic microcontroller
Introduction to pic microcontrollerIntroduction to pic microcontroller
Introduction to pic microcontroller
 
PIC 16F877 micro controller by Gaurav raikar
PIC 16F877 micro controller by Gaurav raikarPIC 16F877 micro controller by Gaurav raikar
PIC 16F877 micro controller by Gaurav raikar
 
Programming with PIC microcontroller
Programming with PIC microcontroller Programming with PIC microcontroller
Programming with PIC microcontroller
 
PIC CONTROLLERS
PIC CONTROLLERSPIC CONTROLLERS
PIC CONTROLLERS
 
Arm7 Interfacing examples
Arm7   Interfacing examples Arm7   Interfacing examples
Arm7 Interfacing examples
 
Pic microcontroller step by step your complete guide
Pic microcontroller step by step your complete guidePic microcontroller step by step your complete guide
Pic microcontroller step by step your complete guide
 
Pic 18 microcontroller
Pic 18 microcontrollerPic 18 microcontroller
Pic 18 microcontroller
 
Arm7 document
Arm7  documentArm7  document
Arm7 document
 

Semelhante a Chapter5 dek3133

analog to digital converter and dac final
analog to digital converter and dac finalanalog to digital converter and dac final
analog to digital converter and dac final
DrVikasMahor
 
Interfacing technique with 8085- ADC[0808]
Interfacing technique with 8085- ADC[0808]Interfacing technique with 8085- ADC[0808]
Interfacing technique with 8085- ADC[0808]
Guhan k
 
adcanddac hai kya bhayy me know if-01.pptx
adcanddac hai kya bhayy me know if-01.pptxadcanddac hai kya bhayy me know if-01.pptx
adcanddac hai kya bhayy me know if-01.pptx
shivraj3252
 
digitalvoltmeterusing805112b2-170214173216 (1).pdf
digitalvoltmeterusing805112b2-170214173216 (1).pdfdigitalvoltmeterusing805112b2-170214173216 (1).pdf
digitalvoltmeterusing805112b2-170214173216 (1).pdf
satyamsinha37
 
05 analog control_sp15
05 analog control_sp1505 analog control_sp15
05 analog control_sp15
John Todora
 
Chp7 pic 16 f84 interfacing - copy
Chp7 pic 16 f84 interfacing - copyChp7 pic 16 f84 interfacing - copy
Chp7 pic 16 f84 interfacing - copy
mkazree
 

Semelhante a Chapter5 dek3133 (20)

analog to digital converter and dac final
analog to digital converter and dac finalanalog to digital converter and dac final
analog to digital converter and dac final
 
Interfacing technique with 8085- ADC[0808]
Interfacing technique with 8085- ADC[0808]Interfacing technique with 8085- ADC[0808]
Interfacing technique with 8085- ADC[0808]
 
Analog to Digital Converters
Analog to Digital ConvertersAnalog to Digital Converters
Analog to Digital Converters
 
Pic ppt 13104022(4th_year)
Pic ppt 13104022(4th_year)Pic ppt 13104022(4th_year)
Pic ppt 13104022(4th_year)
 
adcanddac hai kya bhayy me know if-01.pptx
adcanddac hai kya bhayy me know if-01.pptxadcanddac hai kya bhayy me know if-01.pptx
adcanddac hai kya bhayy me know if-01.pptx
 
8051 FINIAL
8051 FINIAL8051 FINIAL
8051 FINIAL
 
Unit iv microcontrollers final
Unit iv microcontrollers finalUnit iv microcontrollers final
Unit iv microcontrollers final
 
UNIT 4 & 5 - I nterfacing_Lecture7.pptx
UNIT 4 & 5 - I         nterfacing_Lecture7.pptxUNIT 4 & 5 - I         nterfacing_Lecture7.pptx
UNIT 4 & 5 - I nterfacing_Lecture7.pptx
 
Fundamental of MSD Module-III Part-a.ppt
Fundamental of MSD Module-III Part-a.pptFundamental of MSD Module-III Part-a.ppt
Fundamental of MSD Module-III Part-a.ppt
 
Adc interfacing
Adc interfacingAdc interfacing
Adc interfacing
 
ADC and DAC interfacing.pdf
ADC and DAC interfacing.pdfADC and DAC interfacing.pdf
ADC and DAC interfacing.pdf
 
Unit iii microcontrollers final1
Unit iii microcontrollers final1Unit iii microcontrollers final1
Unit iii microcontrollers final1
 
8255
82558255
8255
 
Analog To Digital Conversion (ADC) Programming in LPC2148
Analog To Digital Conversion (ADC) Programming in LPC2148Analog To Digital Conversion (ADC) Programming in LPC2148
Analog To Digital Conversion (ADC) Programming in LPC2148
 
DIGITAL VOLTMETER USING 8051 MICROCONTROLLER
DIGITAL VOLTMETER USING 8051 MICROCONTROLLERDIGITAL VOLTMETER USING 8051 MICROCONTROLLER
DIGITAL VOLTMETER USING 8051 MICROCONTROLLER
 
digitalvoltmeterusing805112b2-170214173216 (1).pdf
digitalvoltmeterusing805112b2-170214173216 (1).pdfdigitalvoltmeterusing805112b2-170214173216 (1).pdf
digitalvoltmeterusing805112b2-170214173216 (1).pdf
 
05 analog control_sp15
05 analog control_sp1505 analog control_sp15
05 analog control_sp15
 
Adc dac converter
Adc dac converterAdc dac converter
Adc dac converter
 
Chp7 pic 16 f84 interfacing - copy
Chp7 pic 16 f84 interfacing - copyChp7 pic 16 f84 interfacing - copy
Chp7 pic 16 f84 interfacing - copy
 
Construction of digital voltmeter by Bapi Kumar Das
Construction of digital voltmeter by Bapi Kumar DasConstruction of digital voltmeter by Bapi Kumar Das
Construction of digital voltmeter by Bapi Kumar Das
 

Mais de Hattori Sidek (20)

Chapter 4 frequency modulation
Chapter 4 frequency modulationChapter 4 frequency modulation
Chapter 4 frequency modulation
 
Chapter 3 am receivers
Chapter 3 am receiversChapter 3 am receivers
Chapter 3 am receivers
 
Ch8 file processing
Ch8 file processingCh8 file processing
Ch8 file processing
 
Ch6 pointers (latest)
Ch6 pointers (latest)Ch6 pointers (latest)
Ch6 pointers (latest)
 
Ch5 array nota
Ch5 array notaCh5 array nota
Ch5 array nota
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
Ch3 selection
Ch3 selectionCh3 selection
Ch3 selection
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Ch1 principles of software development
Ch1 principles of software developmentCh1 principles of software development
Ch1 principles of software development
 
Ch7 structures
Ch7 structuresCh7 structures
Ch7 structures
 
13 atm
13 atm13 atm
13 atm
 
12 wireless la-ns
12 wireless la-ns12 wireless la-ns
12 wireless la-ns
 
11 circuit-packet
11 circuit-packet11 circuit-packet
11 circuit-packet
 
10 high speedla-ns
10 high speedla-ns10 high speedla-ns
10 high speedla-ns
 
9 lan
9 lan9 lan
9 lan
 
8 spread spectrum
8 spread spectrum8 spread spectrum
8 spread spectrum
 
7 multiplexing
7 multiplexing7 multiplexing
7 multiplexing
 
6 data linkcontrol
6  data linkcontrol6  data linkcontrol
6 data linkcontrol
 
5 digital datacomm
5 digital datacomm5 digital datacomm
5 digital datacomm
 

Último

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Último (20)

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 

Chapter5 dek3133

  • 1. Chapter 5 PIC Interfacing
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. Analog to digital conversion (cont..) 16C7X device specifications
  • 8.
  • 9. Analog to digital conversion (cont..) Memory map of PIC 16C711 BANK0 BANK1
  • 10.
  • 11.
  • 12.
  • 13. Analog to digital conversion (cont..) ADCON0 register ADCS1 ADCS0 - CHS1 CHS0 GO/DONE - ADON Bit 7 Bit 0 1 = A/D on 2 = A/D off 1 = A/D in progress 0 = A/D finished Analog channel select 00 = channel 0, AN0 01 = channel 1, AN1 10 = channel 2, AN2 11 = channel 3, AN3
  • 14.
  • 15. Analog to digital conversion (cont..) Bit 7 Bit 0 A/D Port Configuration bits ADCON1 Register ADCON1 Port configuration - - - - - - PCFG1 PCFG0 Vdd D D D D 11 Vdd D D A A 10 A3 Vref A A A 01 Vdd A A A A 00 Ref A3 A2 A1 A0 PCFG
  • 16.
  • 17.
  • 18.
  • 19.
  • 20. Serial Communication (cont..) Pin designations on RS232 connector (Ring Indicator) 9. RI (Clear To Send) 8. CTS (Request To Send) 7. RTS (Data Set Ready) 6. DSR (Ground) 5. GND (Data terminal Ready) 4. DTR (Transmit Data) 3. TXD (Receive Data) 2. RXD (Carrier Detect) 1. CD
  • 21.
  • 22. Serial Communication (cont..) Connecting a microcontroller to a PC via a MAX232 line interface chip Program Example
  • 23.
  • 24.
  • 25.
  • 26. Pulse Width Modulation (PWM) – (Cont..) Figure 1
  • 27. Pulse Width Modulation (PWM) – (Cont..) list p= 16f84 ;************************************************************* PORTB EQU 0x06 ; port b equate duty EQU 0x0c ; length of duty cycle temp EQU 0x0d ; length of duty cycle ;************************************************************* c EQU 0 ; status bit to check after subtraction ;************************************************************* ORG 0x000 The only equate of signifficance here is PWM. This register will be used to store the length of the PWM signal to be generated.
  • 28. Pulse Width Modulation (PWM) – (Cont..) The next portion of code contains the actual instructions that tell the PIC what to do. start MOVLW 0x00 ;load W with 0x00 make port B output TRIS PORTB ;copy W tristate to port B outputs MOVLW 0x00 ;fill w with zeroes MOVWF PORTB ;set port b outputs to low These lines ;set up port B as outputs. ;All outputs are then set to low. rstrt MOVLW d'0' MOVWF PORTB MOVLW d'157' ;Duty cycle length movwf duty After setting up the ports, the main loop is begun. At the beginning of the main loop, all port b pins are set to low just incase they are high when they shouldn't be. The duty cycle is then set to 157 (a 50% duty cycle. 255 corresponds to 100% and 0 corresponds to 0%).
  • 29. Pulse Width Modulation (PWM) – (Cont..) b0loop MOVF duty,w MOVWF temp BSF PORTB ,0 pwma NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP DECFSZ temp GOTO pwma
  • 30. Pulse Width Modulation (PWM) – (Cont..) The next bit of code is the loop for the PWM signal generated at pin B0. The pwm1a loop generates the high portion of the PWM signal. The duty cycle is stored in temp and then the pin is set high. after a pause, temp is decremented and so long as it doesnt reach zero the pause is repeated and temp is decremented again. After temp reaches zero, the code continues.
  • 31. Pulse Width Modulation (PWM) – (Cont..) MOVLW d'255 ' MOVWF temp MOVF duty,w SUBWF temp,f BCF PORTB ,0 pwmb NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP
  • 32. Pulse Width Modulation (PWM) – (Cont..) DECFSZ temp GOTO pwmb GOTO rstrt END The next portion of code generates the low part of the PWM signal. The value 255 is stored in temp, and the duty cycle is subtracted from this. This gives the remaining length of signal to be generated. Temp is then decremented in the same manner as above, this time with B0 set to low. Once the entire PWM signal has been generated, the code repeats. This code causes a PWM signal to be generated with a duty cycle proportional to the value set. The frequency of the signal can also be adjusted by varying the delay (the number of nop's used).
  • 33.
  • 34.