
PICKIT 3 programmer tool setup is attached as resources.
/// MikroC for PIC code
void main() {
TRISB.F7 = 0;
PORTB.F7 = 0;
Delay_ms(100);
TRISD.F2 = 1;
PORTD.F2 = 1;
Delay_ms(100);
while(1)
{
if ( PORTD.F2 == 0 )
{
delay_ms(100);
if ( PORTD.F2 == 0 )
{
PORTB.F7 = 1;
}
}
else
{
PORTB.F7 = 0;
}
}
}
/// MikroC for PIC code
int count = 0;
void main() {
TRISD.F2 = 1;
PORTD.F2 = 1;
Delay_ms(100);
TRISD.F3 = 1;
PORTD.F3 = 1;
Delay_ms(100);
PWM1_Init(5000); // pin 17
Delay_ms(100);
count = 0;
while(1)
{
PWM1_Start();
Delay_ms(20);
if ( PORTD.F3 == 0 )
{
PWM1_Set_Duty(count); // 0 - 255 0 = 0 V while 255 = 5V
count = count + 5;
Delay_ms(50);
}
else if ( PORTD.F2 == 0 )
{
PWM1_Set_Duty(count); // 0 - 255 0 = 0 V while 255 = 5V
count = count - 5;
Delay_ms(50);
}
}
}
MikroC for PIC code file attached as resources. Please download.
//////////////////////////////////////////////////// MikroC for PIC code:
void main() {
TRISB = 0x00;
PORTB= 0x00;
Delay_ms(20);
TRISC.F0 = 1; // start
PORTC.F0 = 0;
Delay_ms(20);
TRISC.F1 = 1; // stop
PORTC.F1 = 0;
Delay_ms(20);
while(1)
{
if ( PORTC.F0 == 1 )
{
Delay_ms(30);
if ( PORTC.F0 == 1 )
{
while(1)
{
if ( PORTC.F1 == 1 )
{
Delay_ms(20);
if ( PORTC.F1 == 1 )
{
break;
}
}
PORTB = 0xFF;
Delay_ms(250);
PORTB= 0x00;
Delay_ms(250);
}
}
}
}
}
MikroC for PIC code files attached as resources. Please download.
MikroC for PIC code files attached as resources. Please download.
MikroC for PIC code files atttached as resources. Please download.
/////MikroC For PIC code
void main() {
TRISD.F1 = 1;
PORTD.F1 = 0;
Delay_ms(100);
TRISB = 0x00;
PORTB = 0x00;
Delay_ms(100);
while(1)
{
if( PORTD.F1 == 1 )
{
Delay_ms(20);
if( PORTD.F1 == 1 )
{
PORTB.F0 = 1;
Delay_ms(1000);
if( PORTD.F1 == 1 )
{
PORTB.F1 = 1;
Delay_ms(1000);
if( PORTD.F1 == 1 )
{
PORTB.F2 = 1;
Delay_ms(1000);
if( PORTD.F1 == 1 )
{
PORTB.F3 = 1;
Delay_ms(1000);
if( PORTD.F1 == 1 )
{
PORTB.F4 = 1;
Delay_ms(1000);
if( PORTD.F1 == 1 )
{
PORTB.F5 = 1;
Delay_ms(1000);
if( PORTD.F1 == 1 )
{
PORTB.F6 = 1;
Delay_ms(1000);
}
}
}
}
}
}
}
}
else
{
PORTB = 0x00;
}
}
}
///////////////////////////////////////////////////// MikroC for PIC Code:
// Lcd pinout settings
sbit LCD_RS at RC0_bit;
sbit LCD_EN at RC1_bit;
sbit LCD_D7 at RC4_bit;
sbit LCD_D6 at RD3_bit;
sbit LCD_D5 at RD2_bit;
sbit LCD_D4 at RC2_bit;
// Pin direction
sbit LCD_RS_Direction at TRISC0_bit;
sbit LCD_EN_Direction at TRISC1_bit;
sbit LCD_D7_Direction at TRISC4_bit;
sbit LCD_D6_Direction at TRISD3_bit;
sbit LCD_D5_Direction at TRISD2_bit;
sbit LCD_D4_Direction at TRISC2_bit;
int count;
char count1[3];
void main() {
Lcd_Init();
Delay_ms(100);
Lcd_Cmd(_LCD_CURSOR_OFF);
Delay_ms(10);
Lcd_Cmd(_LCD_CLEAR);
TRISB.F0 = 1; // add
PORTB.F0 = 0;
Delay_ms(100);
TRISB.F1 = 1; /// sub
PORTB.F1 = 0;
Delay_ms(100);
count = 0;
while(1)
{
if ( PORTB.F0 == 1 )
{
while(1)
{
if ( PORTB.F0 == 0 )
{
break;
}
}
count = count + 1;
}
else if ( PORTB.F1 == 1 )
{
while(1)
{
if ( PORTB.F1 == 0 )
{
break;
}
}
count = count - 1;
}
else
{
IntToStr(count, count1);
Lcd_Out(1, 1, count1);
Lcd_Out(1, 7, " ");
}
}
}
///////////////////////////////////////////////////// MikroC for PIC code:
// Lcd pinout settings
sbit LCD_RS at RC0_bit;
sbit LCD_EN at RC1_bit;
sbit LCD_D7 at RC4_bit;
sbit LCD_D6 at RD3_bit;
sbit LCD_D5 at RD2_bit;
sbit LCD_D4 at RC2_bit;
// Pin direction
sbit LCD_RS_Direction at TRISC0_bit;
sbit LCD_EN_Direction at TRISC1_bit;
sbit LCD_D7_Direction at TRISC4_bit;
sbit LCD_D6_Direction at TRISD3_bit;
sbit LCD_D5_Direction at TRISD2_bit;
sbit LCD_D4_Direction at TRISC2_bit;
void main() {
Lcd_Init();
Delay_ms(100);
Lcd_Cmd(_LCD_CURSOR_OFF);
Delay_ms(10);
Lcd_Cmd(_LCD_CLEAR);
TRISB.F0 = 1; // shift right button
PORTB.F0 = 0;
Delay_ms(100);
TRISB.F1 = 1; // shift left button
PORTB.F1 = 0;
Delay_ms(100);
while(1)
{
if ( PORTB.F0 == 1 )
{
Delay_ms(50);
if ( PORTB.F0 == 1 )
{
Lcd_Cmd(_LCD_SHIFT_RIGHT);
}
}
else if ( PORTB.F1 == 1 )
{
Delay_ms(50);
if ( PORTB.F1 == 1 )
{
Lcd_Cmd(_LCD_SHIFT_LEFT);
}
}
Lcd_Out(1, 1, "LM");
Delay_ms(300);
}
}
///////////////////////////////////////////////////// MikroC for PIC code:
// Lcd pinout settings
sbit LCD_RS at RC0_bit;
sbit LCD_EN at RC1_bit;
sbit LCD_D7 at RC4_bit;
sbit LCD_D6 at RD3_bit;
sbit LCD_D5 at RD2_bit;
sbit LCD_D4 at RC2_bit;
// Pin direction
sbit LCD_RS_Direction at TRISC0_bit;
sbit LCD_EN_Direction at TRISC1_bit;
sbit LCD_D7_Direction at TRISC4_bit;
sbit LCD_D6_Direction at TRISD3_bit;
sbit LCD_D5_Direction at TRISD2_bit;
sbit LCD_D4_Direction at TRISC2_bit;
void main() {
Lcd_Init();
Delay_ms(100);
Lcd_Cmd(_LCD_CURSOR_OFF);
Delay_ms(10);
Lcd_Cmd(_LCD_CLEAR);
TRISB.F0 = 1; // Input 2
PORTB.F0 = 0;
Delay_ms(100);
TRISB.F1 = 1; /// Input 1
PORTB.F1 = 0;
Delay_ms(100);
TRISB.F2 = 0; // LED 2
PORTB.F2 = 0;
Delay_ms(100);
TRISB.F3 = 0; /// LED 1
PORTB.F3 = 0;
Delay_ms(100);
while(1)
{
if ( PORTB.F1 == 1 )
{
Delay_ms(20);
if ( PORTB.F1 == 1 )
{
PORTB.F3 = 1;
Lcd_Out(1, 1, "Input 1");
Delay_ms(100);
Lcd_Out(1, 1, " ");
}
}
else if ( PORTB.F0 == 1 )
{
Delay_ms(20);
if ( PORTB.F0 == 1 )
{
PORTB.F2 = 1;
Lcd_Out(1, 1, "Input 2");
Delay_ms(100);
Lcd_Out(1, 1, " ");
}
}
else
{
PORTB.F2 = 0;
PORTB.F3 = 0;
Lcd_Out(1, 1, "No Input");
Delay_ms(40);
Lcd_Out(1, 1, " ");
}
}
}
///// MikroC for PIC code
void main() {
UART1_Init(9600);
Delay_ms(100);
TRISD.F1 = 1;
PORTD.F0 = 0;
Delay_ms(100);
while(1)
{
if ( PORTD.F1 == 1 )
{
Delay_ms(50);
if ( PORTD.F1 == 1 )
{
UART1_Write_Text("AT+CMGF=1\r\n");
Delay_ms(400);
UART1_Write_Text("AT+CMGS=\"+923498622243\"\r\n");
Delay_ms(400);
UART1_Write_Text("Learning Microcontrollers\r\n");
Delay_ms(50);
UART1_Write_Text("Button Pressed\r\n");
Delay_ms(50);
UART1_Write_Text("Tutorial\r\n");
Delay_ms(50);
UART1_Write(26); /// = ctrl+zin mikroC
Delay_ms(4000);
}
}
else
{
}
}
}
MikroC for PIC code files are attached as resouces. Please download.
Hello Guys,
This course will teach you about how you can interface push buttons with PIC16F877A microcontroller to make various projects like incrementing decrementing counters on 7-segment, controlling brightness of LEDs, triggering certain sequecnes on/off etc.
Every lecture have its corresponding mikroC for PIC code in the description. Just copy paste that in your compiler. Some lectures have code files in the resources for you to download, just open .c file and copy the code in your compliler.
You will learn about making the circuit. Every lecture have a presentation where I show you pin by pin how to do the wiring and setup the hardware.
The 1st and 2nd section is introduction which teaches you how to setup the microcontroller for programming. And then 3rd section is the project based tutorials.
Here is the outline:
Introduction to PIC16F877A.
Lecture 1: PIC16F877A a basic introduction.
Lecture 2: Extracting useful data from the datasheet of PIC16F877A.
Lecture 3: Pins and ports of PIC16F877A.
Lecture 4: Setting up a PIC16F877A for programming.
Download and install PICKIT 3 programmer tool and MikroC for PIC compiler.
Lecture 5: Downloading and installing MikroC for PIC.
Lecture 6: Downloading and installing PICKIT 3 programmer tool.
Push button based projects with PIC16F877A.
Lecture 7: PIC16F877A interface Push Button. Using MikroC for PIC coding.
Lecture 8: PIC16F877A LED brightness control using push buttons tutorial.
Lecture 9: PIC16F877A interface 4 digit 7 segment display. Increment and decrement counting
Lecture 10: Start and stop LED blinking using push buttons. PIC16F877A tutorial.
Lecture 11: PIC16F877A based caller / receiver circuit using LEDs and push buttons.
Lecture 12: PIC16F877A LED blinking with speed control using push buttons.
Lecture 13: Start/stop LED blinking sequence using push buttons with PIC16F877A.
Lecture 14: Stepper motor control using push button with PIC16F877A.
Lecture 15: Use single momentary push button’s press time to do various task using PIC16F877
Lecture 16: Increment and decrement a counter using 2 push buttons on LM016 LCD.
Lecture 17: Shift text left/right on 16 x 2 LM016 LCD using 2 push buttons with PIC16F877A.
Lecture 18: Display 2 inputs received from 2 push buttons on 16x2 LM016 LCD with LED.
Lecture 19: Use push button to send SMS from PIC16F877A to your phone using SIM800L module.
Lecture 20: 2 Push buttons to control brightness of 2 LEDs at same time using 2 PWM channels