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

keyboard interface to 16f628

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








keyboard interface to 16f628
PostPosted: Tue Nov 08, 2005 6:56 pm     Reply with quote

This code read input from the keyboard using the 16f628. I m using loop to detect the clock signal from the keyboard. I have learned that this can be done by using interrupt. Can anybody teach me how to do this?

--------------------------------------------------------------------------------------
void kbd(int n); //send keyboard input through rs232

int clk=0;
int c1=0;
int c2=0;

void main()
{
WHILE(TRUE) {

if(!input(pin_b3) && flg==false) { //when the keyboard clock goes low
flg=true;

if(input(pin_b0)) { //data of keyboard
if(clk==1) c2+=1;
else if(clk==2) c2+=2;
else if(clk==3) c2+=4;
else if(clk==4) c2+=8;
else if(clk==5) c1+=1;
else if(clk==6) c1+=2;
else if(clk==7) c1+=4;
else if(clk==8) c1+=8;
}
clk++;

if(clk==11) {
output_low(pin_b3); //halt the keyboard from sending data
kbd(c2+(c1*16));
c1=c2=0;
output_high(pin_b3);
clk=0;
}
}
else if(input(pin_b3) && flg==true) {
flg=false;
}
}
}
--------------------------------------------------------------------------------------
leesing2k3



Joined: 08 Nov 2005
Posts: 28

View user's profile Send private message

PostPosted: Wed Nov 09, 2005 6:22 am     Reply with quote

Code:

void kbd(int n);                                             //send keyboard input through rs232

int clk=0;
int c1=0;
int c2=0;

void main()
{
   WHILE(TRUE) {

      if(!input(pin_b3) && flg==false) {                    //when the keyboard clock goes low
         flg=true;

         if(input(pin_b0)) {                                //data of keyboard
            if(clk==1) c2+=1;
            else if(clk==2) c2+=2;
            else if(clk==3) c2+=4;
            else if(clk==4) c2+=8;
            else if(clk==5) c1+=1;
            else if(clk==6) c1+=2;
            else if(clk==7) c1+=4;
            else if(clk==8) c1+=8;
         }
         clk++;

         if(clk==11) {
            output_low(pin_b3);                              //halt the keyboard from sending data
            kbd(c2+(c1*16));
            c1=c2=0;
            output_high(pin_b3);
            clk=0;
         }
      }
      else if(input(pin_b3) && flg==true) {
         flg=false;
      }
   }
}
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