CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Counter with lcd

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
Kumara



Joined: 16 Oct 2013
Posts: 7
Location: Sri Lanka

View user's profile Send private message

Counter with lcd
PostPosted: Thu Oct 17, 2013 10:49 am     Reply with quote

This will help for beginners. Lcd.c driver is available in Picc\Drivers (CCS C Compiler).
Code:

// Program function: Digital counter with LCD.                 
// Target processor 16F877A (20 MHZ)
// Written by Kumara                           

#include <16F877A.h>              // Pic Microcontroller (MCU)
#DEVICE ADC=10                    // 8 Bit analog resolution
#fuses NOWDT,HS, NOPUT, NOPROTECT // Fuses
#fuses NOBROWNOUT, NOLVP          // Fuses
#use delay(clock=20000000)        // Crystal Oscillator Frequency ( 20 MHZ)

#include <lcd.c>                  // Driver for LCD Module ( PICC\DRIVERS )



   void main()                    // Main block
   {


   INT16 PRE_COUNT=0;             // Declare variable
   INT16 SET_COUNT;               // Declare variable
   INT1 SW1;                      // Declare variable
   BOOLEAN ISPRESSED=FALSE;       // Boolean logic=0;



   setup_adc_ports(AN0);
   setup_adc(ADC_CLOCK_INTERNAL);
 


   lcd_init();
   
   while (TRUE) {                // Endless loop

   SW1=INPUT(PIN_C0);            // Positive inputs

         IF(PRE_COUNT==0)
         {
         lcd_putc("\f");         // LCD clear
         lcd_gotoxy(1,1);        // Select Raw 1 & start digit 1 position
         printf(lcd_putc," PRE_COUNT:%04LU ",PRE_COUNT);

         lcd_gotoxy(1,2);        // Select Raw 2 & start digit 1 position
         printf(lcd_putc," SET_COUNT:%04LU ",SET_COUNT);
         DELAY_MS(200);
         }

         ////////////////////////////////////////////////////////

         SET_ADC_CHANNEL(0);     // INPUT AN0
         DELAY_US(100);
         SET_COUNT=READ_ADC();   // SET VALUE= RA1 ( 10K V/R )
         SET_COUNT=(SET_COUNT);  // FOR 4 DIGITS UP TO 1023
         ////////////////////////////////////////////////////////

         IF (SW1 && !ISPRESSED) 
         {

         DELAY_MS(10);           

         SW1=INPUT(PIN_A1);     
         IF(SW1)                 
         {PRE_COUNT++;           

         ISPRESSED=TRUE;         

         lcd_putc("\f");         // LCD clear

         lcd_gotoxy(1,1);        // Select Raw 1 & start digit 1 position
         printf(lcd_putc," PRE_COUNT:%04LU ",PRE_COUNT);

         lcd_gotoxy(1,2);        // Select Raw 2 & start digit 1 position
         printf(lcd_putc," SET_COUNT:%04LU ",SET_COUNT);
         DELAY_MS(100);


         IF(PRE_COUNT>=SET_COUNT)
            {
            OUTPUT_HIGH(PIN_B0);

            }
         ELSE
            {
            OUTPUT_LOW(PIN_B0);

            }
       }
   }

         IF(!SW1)                 // This line must be here
         {
         ISPRESSED=FALSE;         // This line must be here

         }
     }
 }

Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group