Course On Microcontrollers
Course On Microcontrollers
&
Abdur Rahman Noble arnoble072@gmail.com Mobile:01670225958
What is a Microcontroller?
Mini-Computer
Microprocessor
The Brains Arithmetic Logic Unit (ALU) Control Unit
History
The first microprocessor was developed by what was then a small company called Intel (short for Integrated Electronics) in the early 1970s. The chipset was a success and within a short while Intel developed a general purpose 4 bit microprocessor called the 4004. In 1974 the more powerful second generation microprocessor (the 8008) wasannounced fabricated as a single chip.
Why Important?
Embedded Inside:
Automotive systems Airplanes Toys Medical Devices Furniture
Billions of units
Available uC in Bangladesh
AT89C51 AT89C52 AT89S51 AT89S52 ATMEGA-8 AT89C2051 AT89C4051 AT89C55WD AT89S8252 AT90S2313 AT90S8515 AT90S8535 ATMEGA-16 ATMEGA-32 ATMEGA-64 ATMEGA-88 ATTINY-13 ATTINY-15 ATTINY-26 AT89C51ED2 AT89C51RD2 AT91RM9200 AT91SAM256 ATMEGA-128 ATMEGA-162 W78E052B40DL
Available uC in Bangladesh
PIC16F72 PIC16F74 PIC16F77 PIC10F200 PIC12F629 PIC16C54C PIC16C65B PIC16F676 PIC18F452 PIC16F628A PIC16F873A PIC16F877A PIC18F4550 PIC16F73 PIC16F76 PIC16F88 PIC12F508 PIC12F675 PIC16C57C PIC16C923 PIC16F84A PIC16C622A PIC16F648A PIC16F876A PIC18F2550
PIC16F690
20-Pin Flash-Based, 8-Bit CMOS Microcontrollers with nanoWatt Technology
Wide operating voltage range (2.0V-5.5V) 17 I/O pins and 1 input only Two 8-bit Timer, One 16-bit Timer 12-channel, 10-bit ADC Programmable Serial USART Internal Calibrated RC Oscillator DC 20 MHz oscillator/clock input Software selectable frequency range of 8 MHz to 32 kHz
Pin Diagram
Software Installation
1. 2. 3.
When installation is completed, run Crack Proteus 7.2 SP6 PRO v1.1 and select the folder where the proteus is installed.
Open MPLAB
Start -> All Programs -> Microchip -> MPLAB IDE ver 8.60 -> MPLAB IDE
Project -> Project Wizard from MPLAB IDE and this will launch the project wizard, just continue with Next
END OF CLASS -1
I/O Port
For Port A, B, C there are control bytes TRISx. Setting a TRISx bit (= 1) will make the corresponding PORTx pin an input Clearing a TRISx bit (= 0) will make the corresponding PORTx pin an output
{
int y; for(y=0;y<=6500;y++) { } } void main() {
TRISC=0X00;
TRISA0=0; TRISB=0X00; while(1) { PORTC=1;
RA0=1;
Maximum output current sunk by any I/O pin .................................................................................................... 25 mA Maximum output current sourced by any I/O pin .............................................................................................. 25 mA Maximum current sunk by PORTA, PORTB and PORTC (combined) ............................................................ 200 mA
Maximum current sourced PORTA, PORTB and PORTC (combined) ............................................................ 200 mA
Input
Input Arrangement
For hardware side, use 1uf-10uf Capacitor across the push button if the input source is a push button. Solve the de-bouncing problem by programming accordingly.
Class work
END OF CLASS 3
Block Diagram
Related Pins
Configuration Sequence
Enable ADC Analog input channel declaration Channel Selection Clock Selection Start a conversion Wait until the conversion finishes When the conversion is done, read the 8 bit LSB from ADRESL and 2 bit MSB from ADRESH byte. Concatenate them to get 10 bit conversion
Configuration Bytes
There are four registers available to control the functionality of the A/D module: 1. ANSEL 2. ANSELH 3. ADCON0 4. ADCON1
Enabling ADC
CHANNEL SELECTION
There are fourteen analog channels The CHS<3:0> bits (ADCON0<5:2>) control which channel is connected to the sample and hold circuit.
VOLTAGE REFERENCE
There are two options for the voltage reference to the A/D converter: either VDD is used or an analog voltage applied to VREF is used. The VCFG bit (ADCON0<6>)controls the voltage reference selection. If VCFG is set, then the voltage on the VREF pin is the reference;otherwise, VDD is the reference.
Voltage Reference
CONVERSION CLOCK
The source of the conversion clock is software selectable via the ADCS bits (ADCON1<6:4>).
STARTING A CONVERSION
The A/D conversion is initiated by setting the GO/DONE bit (ADCON0<1>). When the conversion is complete, the A/D module: Clears the GO/DONE bit
CONVERSION OUTPUT
The A/D conversion can be supplied in two formats: Left or right justified. The ADFM bit (ADCON0<7>) controls the output format.
END OF CLASS 4
Interrupt
Basics of Interrupt
Interrupted operation while normal operation is going on Very good option for taking input
Interrupt Basic
So far functions were called from the main program or other functions. The interrupt functions is called by the hardware itself and operates by following steps: After the interrupt function is loaded into the memory, the function waits for a moment for the interrupt to occur; When the interrupt has occurred, the operating system stops the execution of the main function and free itself to perform the interrupt function; After the execution of the interrupt function, the operating system continues to run the main function from the place it stopped before the interrupt has occurred.
Interrupt Pins
Interrupts
Interrupt Configuration
RA2/INT Must be configured as Digital I/O Interrupt Mode selection Initializing the flag bit Enable External Interrupt Enable Global interrupt In the Interrupt service routine, clear flag bit every time.
Mode Selection
When a valid edge appears on the RA2/INT pin, the INTF bit (INTCON<1>) is set.
The INTF bit must be cleared in software in the Interrupt Service Routine before re-enabling this interrupt.
void interrupt test(void) // Interrupt function definition { if (INTF==1) { INTF=0; .. } }
END OF CLASS 5
Timer/ Counter
3 timers/Counters Two 8-bit timers and One 16-bit timer Easily selectable clock source
Its a 8 or 16 bit register. Its value increases with each clock cycle. So, bigger the no of bits, the bigger the range of counting. By setting modes, we can calculate intervals or generate events at regular interval.
Timer0 Diagram
Timer Configuration
Clock selection Mode Selection Interrupt configuration
The external clock source must be at least 2.5 less than the C clock source.
Clock Source
The internal clock can be used as the clock source. For timers, the internal clock can be pre-scaled. There is option for external clock source also.
Timer1
END OF CLASS 6
USART
Universal Synchronous and Asynchronous serial Receiver and Transmitter
Full Duplex Operation (Independent Serial Receive and Transmit Registers) Asynchronous or Synchronous Operation Master or Slave Clocked Synchronous Operation
Synchronous
Clock source is synchronized Data is synchronized with clock i.e. a common clock source for the communicating devices is necessary
Asynchronous
No common clock source is required Clock is recognized by the receiver automatically
Clock Generation
PORT Configuration
In order to configure pins RB6/SCK/SCL and RB7/TX/CK as the Universal Synchronous Asynchronous Receiver Transmitter: SPEN (RCSTA<7>) bit must be set (= 1), TRISB<6> bit must be set (= 1), and TRISB<7> bit must be set (= 1).
Transmission
Receiver Enabling
END OF CLASS 7
6 February 2010
CLASS 8
Analog Comparator
Comparator Enabling
Comparator Output
END OF CLASS 8