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 support@ccsinfo.com

Two Seven segment and two Switch

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Nisar



Joined: 16 Nov 2007
Posts: 20

View user's profile Send private message

Two Seven segment and two Switch
PostPosted: Sun Mar 15, 2009 1:23 pm     Reply with quote

Hello everybody

I want to increment by one is executed continuously only when S1 switch is pressed. When the switch is released, the increment stops. When S2 switch is pressed, it initiates a decrement continuously by one. Using two seven segment and two switch. S1 and S2 are connected on PIC16F877 PortB pins RB1 and RB2. Plz help me.

My C Code for continuously counting from 00 to 99 are here
Code:

#include<16f877.h>
#fuses XT,NOLVP,NOWDT,PUT
#use delay (clock=4000000)   // defind crystal = 4MHz
#byte port_d=8
#byte port_a=5
byte CONST LED_MAP[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0x90};

//===========================================
// this function use to display number 00=99
// input : n = number to display
//===========================================
void display_number(int n)
{

   output_d(LED_MAP[n/10]);//tens position;n=0 to 9
   output_low(PIN_A1);
   delay_ms(2);
   output_high(PIN_A1);
   output_d(LED_MAP[n%10]) ;//unit position
   output_low(PIN_A0);
   delay_ms(2);
   output_high(PIN_A0);
}
//============================================
// main program
//============================================
void main()
{
   int i,count=1;

   while(TRUE)
   {
      for (i=0;i<=200;i++)
         display_number(count);      // dispay 200 times
    count=(count==99) ? 1: count+1;//count+1=++count

   }
}


Thanks
Nisar
Laxmi
Guest







Re: Two Seven segment and two Switch
PostPosted: Mon Oct 05, 2009 11:49 pm     Reply with quote

Code:

if(RB4)       // RB4    for IN_SENSOR
     {
                     
      while(RB4)
      {
         continue;
      }

      DelayMs(2);         // Delay for debounce
           
        if(count<=99)
       {
            count++;
          display_number_both_tens_unit(count);
       }
   
       }
     else
      { /* for Down-counter*/
      if(RB5)         // RB5 for OUT_SENSOR
       {
     
        while(RB5)
         {
           continue;
         }
         
         DelayMs(2);      // Delay for Debounce
            count--;
            display_number_both_tens_unit(count);
         }
       
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion 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