Skip to main content

Experiment No. 1 : 4-Bit Binary Counter

Experimental Setup:
The first experiment that we are going to do with our PIC16F628A board is a 4-bit binary counter that counts from 0(00h) to 15(0Fh) with 1sec delay between each count. The output will be at RB.0 through RB.3 and will be displayed on 4 LEDs. Use four jumper wires to connect RB.0 through RB.3 to LEDs. The picture below shows these connections.


Figure 1. Jumper Connections for a 4-bit Binary Counter



Software:
Here is the C program written for mikroC for PIC 2009 compiler.
/*
 * Project name:
     4-bit Counter
 * Copyright:
     (c) Rajendra Bhatt, 2009.
 * Description:
     This is a simple 4-bit counter. The output will be displayed on 4 LEDs
     connected to PORT RB.0-RB.3
 * Test configuration:
     MCU:             PIC16F628A
     Dev.Board:       PIC16F628A Board
     Oscillator:      XT, 04.0000 MHz

*/
void main() {

  TRISB = 0x00;          // set direction to be output
  PORTB = 0x00;        // Turn OFF LEDs on PORTB
  do {
    Delay_ms(1000);      // 1 second delay
    PORTB ++ ;
  } while(PORTB < 0x0F);            // Till PORTB < 15
}

Experiment Output Video:


Comments

  1. i have a question. i write the program in micro C, i compiled and i got .hex file. I make the board and i want to program de pic with jdm programator using IC-prog. How i select the internal osc of the pic? Or the external osc?

    ReplyDelete
  2. You should be able to change the options with Edit Project window. I recommend to read this:
    http://www.mikroe.com/pdf/mikroc_pic_pro/1st_project_c_pro_pic_v101.pdf

    ReplyDelete
  3. Thanks, I read that and now i have a lot of questions.

    At the oscillator is write HS (HS- Crystl upto 20MHz) and i supose this is n external oscillator because in the data sheet is write 4MHZ internal. Another option is XT (XT- Crystal up to 4.096) and that what kind of oscilator is it?
    ExtClk - external clock from crystal oscilator, etc. Wwhat is this option?
    IntRC I/O -Internal 4MHz & the oscillator lines become I/O is the internal oscillator?

    The last question: what you selected when you make the program in C and write on the PIC?

    ReplyDelete
  4. The HS (High Speed, 4-20 MHz), XT(up to 4 MHz), and LP (Low Power, 32.768KHz) modes all require external crystals. I am using an external 4MHz crystal, so I am using XT mode.
    INTOSC is for internal oscillator modes. Remember that PIC oscillator input pins are multiplexed with digital I/O pins. This means, if you want to use internal oscillator, then you can use pins 12 and 13 of PIC16F628A as digital I/O pins (RB6 and RB7). Read the datasheet for PIC16F628A further details.
    The option EC is for external clock which is sometimes used to synchronize the PIC with some other circuits that already have got clock.

    ReplyDelete
  5. Hi Raj I want help to write code in ccs for something like this:

    1. PIC18F2220
    2. 4 x 74HC373 connected to PORT B(B0-B7) through a bus wire in Isis Professional 7 software.
    3. 4 x 7-Segment Common Anode connected to outputs of 74HC373.
    4. The LE pins of 74HC373 are connected to Port C(C1-C4).
    5. There is a Switch connected to RC0.
    6. When you close the Switch(RC1) the program must display a value from 0-9999 on the 7-Segs and when you open the switch at any moment it should stop counting when you close it again it should start fron 0 again. e.g. like a stopwatch.

    Thanks in advance.

    ReplyDelete
  6. First of all, I don't use CCS but I hope that won't be very different. Your project doesn't seem that difficult. All you need to do is to connect the inputs of all 74HC373 in parallel so that the data from the PIC could be sent to all the latch ICs but will be read only the one whose LE is active. You don't even need time-division multiplexing among the 4-displays, as the digit to be displayed on individual displays will be latched separately.

    ReplyDelete
  7. Hi, Raj am just developed interest in PIC MCU i have bought a PIC 16F628,an 5x7 Dot matrix display, and other electronic components,am hoping to buy more others. pliz guide on how to make a running message display, if possible, your advice on the the type of compiler and the actual program code will be of great help.

    ReplyDelete

Post a Comment

Popular posts from this blog

Contact less tachometer using PIC16F628A

Introduction Tachometer is a device that gives you the information about the rotational speed of any shaft or disc. It usually measures the speed in revolutions per minute (RPM). Today we are going to make a simple tachometer that could measure the rotation speed of a disk without making any physical contact (that's why it is contact less) with the rotating object. The range of this tachometer is 0 - 9999 RPM and displays the RPM on a multiplexed 4-digit seven-segment display. Of course, we are going to do this project on our usual PIC16F628A development board. Infrared sensor Contact-less measurement of RPM will be achieved through an IR sensor. An IR diode will send a beam of infrared towards the rotating disc, and any reflected pulse will be received by a photo diode. The resistance of a photo diode drops drastically when exposed to infrared. An infrared is reflected by a white surface and absorbed by the dark ones. The test disc for this project is shown below. You can see ...

PIC16F628A Development Board

The development board we are going to make for our experimental microcontroller PIC16F628A will look like this. Here are the features it is going to have: Access to all I/O pins through female header pins 4 Push Buttons for Input 4 LEDs for Output An LCD Interface Port A 4-digit Seven-Segment Display Interface LCD Backlight Switch and Contrast Adjustment ICSP Programming (Very Important)

Experiment No. 2 : Push Button and Seven Segment Display Interface

In this experiment, we will program the PIC16F628A as an UP/DOWN Decade Counter. The count value will be displayed on a Seven-Segment Display and will be incremented/decremented by two push buttons on the board. Experimental Setup: The board has built in interface for a multiplexed 4-digit seven segment display (HS-5461AS2 from www.futurlec.com ).We will select only one digit by connecting a Digit Select pin to Vcc, as shown in figure below. A black jumper wire is used for this purpose. The seven segments will be driven through PORTB (already wired on the board). Connect Push Buttons (PB3 and PB4) to RA1 and RA0 female headers using jumper wires.