1. You can now buy finished microcontroller project from us, Check out the Store for the complete list of projects.
  2. Need a custom project, Send us some details about your project. So that we can quote the price for it.

Implementing a 4 bit Counter using an 8051 and Interfacing it to an LCD 1.0

Implementing a 4 bit Counter using an 8051 and Interfacing it to an LCD

  1. Binu
    The program will be used to control a simple 4-bit up-down counter, capable of counting from 0 to 15. At each step the count should be displayed in decimal format on the LCD.
    [​IMG]
    he 4 bit counter has the following functionality:
    The counter has the following input pins :
    a. Reset : when high resets the counter dataout to ``0000''
    b. Updown : decides whether the counter counts up or down.
    c. Load : makes the counter count from the 4 bit input Datain
    d. Datain : which is a 4 bit input count
    The counter has a 4 bit Dataout to reflect the count.
    The count has to be sent to the LCD and displayed in decimal format.
    Code (Text):
    1. #pragma SMALL DB OE
    2. #include
    3. #include "io.h"
    4.  
    5. /* P0, P1, P2 and P3 are predefined port names and are bit addressable */
    6.  
    7. sbit reset = P0^4; /* bit 4 of Port 0 */
    8. sbit up_down = P0^5;
    9. sbit load = P0^6;
    10. sbit Start_LCD = P0^7; /* bit 7 of Port 3 */
    11.  
    12. /* Delay function */
    13. void delay() {
    14.  
    15.         int i, j;
    16.  
    17.         for(i=0; i<1000; i++)
    18.                 for(j=0; j<100; j++)
    19.                         i = i + 0;
    20. }
    21.  
    22. /* Function to output the decimal value of the count on the LCD */
    23. void PrintInt(unsigned char i) {
    24.       char ch[4];
    25.  
    26.       /* Write code to convert the count to a string value and use the
    27.           PrintString function provided in io.c */
    28.  
    29.         PrintString(ch);
    30. }
    31.  
    32. void main(void) {
    33.  
    34.         unsigned char count = 0;
    35.  
    36.         InitIO();  /* Initialize the LCD */
    37.         while (1) {
    38.                 if (Start_LCD == 1) {
    39.                         ClearScreen();
    40.                         PrintString("Ready...");
    41.                         delay();
    42.                 }
    43.                 else if (reset == 1) {
    44.  
    45.                         /* Output 0 on the LCD */
    46.  
    47.                 }
    48.                 else if (load == 1) {
    49.  
    50.                       /* Output the current value of Datain on the LCD */
    51.  
    52.                 }
    53.                 else {
    54.                         /* Check the Up/Down pin for 1 or 0 count up or down
    55.                           accordingly. Display each value on the LCD */
    56.               }
    57.       }
    58. }
    coemplong likes this.
Loading...