PIC microcontroller programming based on micro c IDE.Those who really want to build a base in microcontroller programming,just keep going through this. ;) :)
4. Description
โข PIC โ โPeripheral Interface Controllerโ
โข Made by Microchip Technology
โข Most popular by industry developers and
hobbyists
โ Low cost (cents to dollars)
โ Availability
โ Extensive application notes
โ Serial programming
4
6. SFR(Special Function Register)
โข Registers whose function is predetermined by
the manufacturer of the microcontroller
โข Examples are timers, A/D converter,
oscillators ,etc
7. INPUT / OUTPUT PORTS
โข Microcontroller has one or more registers
(called ports) connected to the microcontroller
pins.
โข Can change a pin function as you wish
8. MEMORY UNIT
โข Memory is part of the microcontroller used for
data storage.
โข Types
1.MROM,
2.OTP ROM, 3.UV EP
ROM, 4.FLASH MEM
5. EEPROM, 6. RAM
9. INTERRUPT
โข Most programs use interrupts in their regular
execution
โข The signal which informs the central processor
unit about such an event is called an
INTERRUPT.
10. CENTRAL PROCESSOR UNIT (CPU)
โข Instruction decoder decodes program
instructions and runs other circuits based on
this
โข Accumulator is a kind of working desk used
for storing all data upon which some
operation should be performed (addition,
shift/move etc.)
โข ALU
11. OSCILLATOR
โข Enable harmonic and synchronous operation of
all circuits within the microcontroller.
โข Usually configured so as to use quartz crystal or
ceramic resonator for frequency stability
โข but it can also operate as a stand-alone circuit
(like RC oscillator).
12. TIMERS/COUNTERS
โข To measure time between two events, it is
sufficient to count up pulses generated by the
oscillator. This is exactly what the timer does.
โข โStopwatchesโ commonly 8- or 16-bit SFRs the
contents of which is automatically incremented
by each coming pulse.
13. HOW DOES THE TIMER OPERATE?
โข It is easy to measure short time intervals, up to
256 microsecond in this mode
โขTo measure time intervals greater than 256 micro
size we use two modified methods
15. COUNTERS
โข If the timer receives pulses form the
microcontroller input pin, then it turns into a
counter.
โข The only difference is that in this case pulses
to be counted come over the microcontroller
input pin and their duration (width) is mostly
undefined.
16. A/D CONVERTER
โข Converts continuous signals to discrete digital
numbers or circuit converts an analogue value
into a binary number and passes it to the CPU
for further processing.
24. PIC 16F877A LAYOUT
Analog I/O
UART
I2C
PORTA
http://www.mikroe.com/eng/chapters/view/74/pic-basic-book-chapter-1-
world-of-microcontrollers/
24
25.
26. FEATURES OF PIC 16F887A
โข RISC architecture
โ Only 35 instructions to learn
โ All single-cycle instructions except branches
โข Operating frequency 0-20 MHz
โข Precision internal oscillator
โ Factory calibrated
โ Software selectable frequency range of 8MHz to 31KHz
โข Power supply voltage 2.0-5.5V
โ Consumption: 220uA (2.0V, 4MHz), 11uA (2.0 V, 32 KHz) 50nA
(stand-by mode)
โข Power-Saving Sleep Mode
โข Brown-out Reset (BOR) with software control option
โข 35 input/output pins
โ High current source/sink for direct LED drive
27. โข 256 bytes EEPROM memory
โ Data can be written more than 1.000.000 times
โข 368 bytes RAM memory
โข A/D converter:
โ 14-channels
โ 10-bit resolution
โข 3 independent timers/counters
โข Watch-dog timer
โข Analogue comparator module with
โ Two analogue comparators
โ Fixed voltage reference (0.6V)
โ Programmable on-chip voltage reference
โข PWM output steering control
โข Enhanced USART module
โ Supports RS-485, RS-232 and LIN2.0
โ Auto-Baud Detect
โข Master Synchronous Serial Port (MSSP)
โ supports SPI and I2C mode
29. Basic codes of MikroC
โข TRISB=0; means that all the pins of PORTB is set
as output. If it is set as 1 then all the pins will be
configured as input.
โข PORTB=0; means that all the pins of PORTB is
Logic low. If it is set as 1 then all the pins will be
set as Logic high state.
โข ANSELA = 0; Configure PORTA pins as digital.
ANSELA = 0b00000101; Means that RA0/C12IN0-
and RA2/C2IN+ pins are analog inputs.
โข ANSELH=0; Configure PORTB pins as digital.
30. โข TRISC.F0 = 1; Makes 0th bit of PORTC Input
โข TRISC.F5 = 0; Makes 5th bit of PORTC Output
โข PORTB.F3 = 1; Makes 3ed bit of PORTB at Logic
High
โข PORTB.F7 = 0; Makes 7th bit of PORTB at Logic
Low
32. Interfacing DC Motor with PIC
Microcontroller using L293D
โข Control Signals and Motor Status
RB0/IN1 RB2/IN2 Motor
Status LOW LOW Stops
LOW HIGH ANT-CLK
HIGH LOW CLK
HIGH HIGH CLK
35. โข /* In this example, PWM module is initialized and set to give a pulse train of 50%
dutycycle.
For this purpose, functions PWM1_Init(), PWM1_Start() and PWM1_Set_Duty()
are used.
All of them are already contained in the mikroC PRO for PIC PWM library and just
need to
be copied to the program. */
unsigned short duty_c; // Define variable duty_c
void initMain() {
ANSEL = ANSELH = 0; // All I/O pins are configured as digital
PORTC = TRISC = 0; // Initial state of port C output pins
PWM1_Init(5000); // PWM module initialization (5KHz)
}
void main() {
initMain();
duty_c = 127; // Initial value of duty-cycle
PWM1_Start(); // Start PWM1 module
PWM1_Set_Duty(duty_c); // Set PWM duty-cycle to 50%
...
36. SERIAL COMMUNICATION
MODULES
โข EUSART
Enhanced Universal Synchronous Asynchronous
Receiver Transmitter (EUSART)module is a serial I/O
communication peripheral unit.
โข also known as Serial
Communications Interface (SCI)
โข contains all clock generators,
shift registers and data buffers
necessary to perform an input/output serial data
transfer
37. โข In order to enable data transmission via
EUSART module it is necessary to define the
state of the following pins-RX , TX
โข RX-Receiver
โข TX-Transmitter
38. /* In this example, internal EUSART module is initialized and set to send back the
message immediately after receiving it. Baude rate is set to 9600 bps. The
program
uses UART library routines UART1_init(), UART1_Write_Text(),
UART1_Data_Ready(),
UART1_Write() and UART1_Read().*/
char uart_rd;
void main() {
ANSEL = ANSELH = 0; // Configure AN pins as digital
C1ON_bit = C2ON_bit = 0; // Disable comparators
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to become stable
UART1_Write_Text("Start");
while (1) { // Endless loop
if (UART1_Data_Ready()) { // If data is received,
uart_rd = UART1_Read(); // read the received data,
UART1_Write(uart_rd); // and send data back via UART
}`
}