Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

defining a value to pushbutton

Status
Not open for further replies.

Rohith_elec

Full Member level 4
Joined
Dec 16, 2011
Messages
198
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,470
How can we define a value to a pushbutton ?

i made a code in mikroC, but some problems in int to ptr


Code:
 // LCD module connections
sbit LCD_RS at RD2_bit;  // for writing to output pin always use latch (PIC18 family)
sbit LCD_EN at RD3_bit;  // for writing to output pin always use latch (PIC18 family)
sbit LCD_D4 at RD4_bit;  // for writing to output pin always use latch (PIC18 family)
sbit LCD_D5 at RD5_bit;  // for writing to output pin always use latch (PIC18 family)
sbit LCD_D6 at RD6_bit;  // for writing to output pin always use latch (PIC18 family)
sbit LCD_D7 at RD7_bit;  // for writing to output pin always use latch (PIC18 family)

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections

#define A Button(&PORTB, 0, 1, 1)
#define B Button(&PORTB, 1, 1, 1)
#define C Button(&PORTB, 2, 1, 1)
#define D Button(&PORTB, 3, 1, 1)




void main() {
char A1,B1,C1,D1;

  ADCON1 |= 0x0F;                    // Configure AN pins as digital
  CMCON  |= 7;                       // Disable comparators
     IntToStr(A,  A1);
     IntToStr(B,  B1);
     IntToStr(C,  C1);
     IntToStr(D,  D1);
     
     
     
  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off

  Lcd_Out(1,6,A1);                 // Write text in first row
  Lcd_Out(2,6,B1);                 // Write text in second row
  Delay_ms(2000);
  Lcd_Cmd(_LCD_CLEAR);               // Clear display

  Lcd_Out(1,1,C1);                 // Write text in first row
  Lcd_Out(2,5,D1);                 // Write text in second row
  Delay_ms(2000);

}
 

Fist of all I don't think it is a good idea to define single letters like A,B,C,D.

You define

Code:
#define A (Button(&PORTB, 0, 1, 1)

and then you use

Code:
 IntToStr(A,  A1);
which translates to
Code:
 IntToStr(Button(&PORTB, 0, 1, 1),  A1);

What is that supposed to do?
I don't see any declaration of a function named Button.
 

Button is a library function in mikroC.
Button library

What exactly do you mean by define a value to push-button?

The button is connected to one pin. So, that pin can read only 0 or 1. You can't make it read an 8-bit integer value. You can have a combination of buttons on PORTB and then read the value of PORTB.

Hope this helps.
Tahmid.
 

I want to make a series of button that holds a value,
like
for each key in keypad, there corresponds a value and we can apply that value in various applications

---------- Post added at 10:31 ---------- Previous post was at 10:18 ----------

The keypad lib in mikroC uses an entire port, i thought to decrease the usage of pins by saving values to buttons

or to give values to a variable when i press a button
 

If you're interested in using just 4 pins, you could use a keypad style configuration and do the PORT reading by yourself without the library. Basically, a keypad, but smaller than 4X4.

Hope this helps.
Tahmid.
 

can i use


Code:
 // LCD module connections
sbit LCD_RS at RD2_bit;  // for writing to output pin always use latch (PIC18 family)
sbit LCD_EN at RD3_bit;  // for writing to output pin always use latch (PIC18 family)
sbit LCD_D4 at RD4_bit;  // for writing to output pin always use latch (PIC18 family)
sbit LCD_D5 at RD5_bit;  // for writing to output pin always use latch (PIC18 family)
sbit LCD_D6 at RD6_bit;  // for writing to output pin always use latch (PIC18 family)
sbit LCD_D7 at RD7_bit;  // for writing to output pin always use latch (PIC18 family)

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections


void main() {
char A1,B1,C1,D1;

  ADCON1 |= 0x0F;                    // Configure AN pins as digital
  CMCON  |= 7;                       // Disable comparators
 
 if (Button(&PORTB, 0, 1, 1)) {  // Detect logical one
      A1 = "A";                 // Update flag
    }
 if (Button(&PORTB, 0, 1, 1)) {  // Detect logical one
      B1 = "B";                 // Update flag
    }
 if (Button(&PORTB, 0, 1, 1)) {  // Detect logical one
      C1 = "C";                 // Update flag
    }
 if (Button(&PORTB, 0, 1, 1)) {  // Detect logical one
      D1 = "D";                 // Update flag
    }
  
    /*IntToStr(A,  A1);
     IntToStr(B,  B1);
     IntToStr(C,  C1);
     IntToStr(D,  D1);*/
     
     
     
  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off

  Lcd_Out(1,6,A1);                 // Write text in first row
  Lcd_Out(2,6,B1);                 // Write text in second row
  Delay_ms(2000);
  Lcd_Cmd(_LCD_CLEAR);               // Clear display

  Lcd_Out(1,1,C1);                 // Write text in first row
  Lcd_Out(2,5,D1);                 // Write text in second row
  Delay_ms(2000);

}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top