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

keypad scan problem

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



Joined: 17 May 2013
Posts: 4

View user's profile Send private message Send e-mail MSN Messenger

keypad scan problem
PostPosted: Fri May 31, 2013 6:22 pm     Reply with quote

hello everyone here again. I will be glad who help me about my project. I would like to tell about it... my project's name is cable cut machine. It was designed by myself but I have a problem ın my ccs c program. I mean I just want to scan once my keypad when I press a button and I want to keep it and then when I press another button again I want to keep it another variable.....

here is my project....
Code:

#include <16f877A.h> // Kullanılacak denetleyicinin başlık dosyası tanıtılıyor.

#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NO DEBUG,NOCPD
#use delay (clock=4000000)

#define use_portb_lcd TRUE // LCD B portuna bağlı

#include <lcd.c> // lcd.c dosyası tanıtılıyor

#define sut1 pin_d0 // sut1 ifadesi pin_d0 ifadesine eşitleniyor
#define sut2 pin_d1 // sut2 ifadesi pin_d1 ifadesine eşitleniyor
#define sut3 pin_d2 // sut3 ifadesi pin_d2 ifadesine eşitleniyor
#define sut4 pin_d3 // sut3 ifadesi pin_d2 ifadesine eşitleniyor

#define sat1 pin_d4 // sat1 ifadesi pin_d4 ifadesine eşitleniyor
#define sat2 pin_d5 // sat2 ifadesi pin_d5 ifadesine eşitleniyor
#define sat3 pin_d6 // sat3 ifadesi pin_d6 ifadesine eşitleniyor
#define sat4 pin_d7 // sat4 ifadesi pin_d7 ifadesine eşitleniyor

char tus=0; // karakter tipinde değişken tanımlanıyor
int32 uzun=0;
int i=0;
int j=0;
int a,b,d,e,f;
int c=0;
int keyoku=0;
const int yarim_adim[]={1,2,4,8};

//*********** Keypad Tarama Fonksiyonu *********

char keypad_oku() // Fonksiyon ismi
{
output_d(0x00); // D portu çıkışı sıfırlanıyor

output_high(sat1); // 1. satır lojik-1 yapılıyor

if (input(sut1)) // 1. sütun okunuyor
   { delay_ms(20); tus=1; }
if (input(sut2)) // 2. sütun okunuyor
   { delay_ms(20); tus=2; }
if (input(sut3)) // 3. sütun okunuyor
   { delay_ms(20); tus=3; }

output_low(sat1); // 1. satır lojik-0 yapılıyor

output_high(sat2); // 2. satır lojik-1 yapılıyor

if (input(sut1)) // 1. sütun okunuyor
   { delay_ms(20); tus=4; }
if (input(sut2)) // 2. sütun okunuyor
   { delay_ms(20); tus=5; }
if (input(sut3)) // 3. sütun okunuyor
   { delay_ms(20); tus=6; }

output_low(sat2); // 2. satır lojik-0 yapılıyor

output_high(sat3); // 3. satır lojik-1 yapılıyor

if (input(sut1)) // 1. sütun okunuyor
   { delay_ms(20); tus=7; }
if (input(sut2)) // 2. sütun okunuyor
   { delay_ms(20); tus=8; }
if (input(sut3)) // 3. sütun okunuyor
   { delay_ms(20); tus=9; }

output_low(sat3); // 3. satır lojik-0 yapılıyor

output_high(sat4); // 3. satır lojik-1 yapılıyor

if (input(sut1)) // 1. sütun okunuyor
   { delay_ms(20); tus=0xE;}
if (input(sut2)) // 2. sütun okunuyor
   { delay_ms(20); tus=0;}
if (input(sut3)) // 3. sütun okunuyor
   { delay_ms(20); tus=0xF; }

output_low(sat4); // 3. satır lojik-0 yapılıyor

return tus; // Fonksiyon "tus" değeri ile geri döner
}

//********** ANA PROGRAM FONKSİYONU*******

void main ( )
{
set_tris_b(0x00); // B portu komple çıkış
set_tris_d(0xF0); // Yüksek değerlikli 4 bit çıkış, düşük değerlikli 4 bit giriş

lcd_init(); // LCD hazırlanıyor

/* printf(lcd_putc,"\fBasilan Tus="); // LCD'ye string yazdırılıyor*/

while(1) // Sonsuz döngü
{
lcd_gotoxy(1,1);
printf(lcd_putc,"kablo kesme");

tus=keypad_oku();

if(input(pin_a0)) /*when you press this button you will entire your cable height */
  {
   d=1;
   lcd_gotoxy(1,1);
   printf(lcd_putc,"\fboy gir");
   delay_ms(10000);
  }

if(d==1)
  {
   lcd_gotoxy(1,1);
   printf(lcd_putc,"\fuzunluk=%d",tus);
   delay_ms(2000);
  }

if(input(pin_a1)) /* custom button*/ /* when you press this button you will entire you price */
  {
   c=1;
   lcd_gotoxy(1,1);
   printf(lcd_putc,"\fadet gir");
   delay_ms(5000);
  }

if(c==1)
  {
   lcd_gotoxy(1,1);
   printf(lcd_putc,"\fadet=%d",tus);
   delay_ms(5000);
   A=lcd_getc(6,1);
   e=1;
  }

if(input(pin_a2)) /* start button */when you press this button our machine is going to work according to your value (height and custom )
  {
   if(e==1)
     {
      for(i=0;i<A;i++)
         {
          output_c(yarim_adim[j]); // Step motor 1 adım ileri
          delay_ms(500);
          j++;
         }
     }
  }
}

}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Jun 01, 2013 1:51 am     Reply with quote

Can you reduce your code to a SHORT sample (say 10 lines), which show your real problem?

Mike
salih_yavuz



Joined: 17 May 2013
Posts: 4

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Sat Jun 01, 2013 3:15 am     Reply with quote

Actually problem is when I press pin_a0 button I want it to scan just one tıme my keypad and secondly when i press pin_a1 button I want it to scan different from pin_a1.
It must be according to my desire ....whenever I press pin_a0 or pin_a1 it must scan my keypad. Do you understand?

Code:

tus=keypad_oku();

if(input(pin_a0)) /*when you press this button you will entire your cable height */
  {
   d=1;
   lcd_gotoxy(1,1);
   printf(lcd_putc,"\fboy gir");
   delay_ms(10000);
  }

if(d==1)
  {
   lcd_gotoxy(1,1);
   printf(lcd_putc,"\fuzunluk=%d",tus);
   delay_ms(2000);
  }

if(input(pin_a1)) /* custom button*/ /* when you press this button you will entire you price */
  {
   c=1;
   lcd_gotoxy(1,1);
   printf(lcd_putc,"\fadet gir");
   delay_ms(5000);
  }

if(c==1)
  {
   lcd_gotoxy(1,1);
   printf(lcd_putc,"\fadet=%d",tus);
   delay_ms(5000);
   A=lcd_getc(6,1);
   e=1;
  }
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