My select button doesn't work in proteus and i don't find a way to solve it.

Thread Starter

dubkey

Joined May 28, 2017
1
Hi i'm trying to make a keypad with 3 button, minus,plus and select. When you want a specific temperature, inc/dec and select one which is in variable temp_set. i attached the circuit and the code, and if someone has a solution to this problem don't hesitate.


CODE IN C:

C:
#include <reg51.h>

sbit RS=P3^0;
sbit RW=P3^1;
sbit E=P3^2;
sbit CS=P3^3;
sbit RDC=P3^4;
sbit WRC=P3^5;
sbit INTR=P3^6;
sbit MINUS=P0^0;
sbit PLUS=P0^1;
sbit SELECT=P0^2;
sbit RELEU=P3^7;

void lcd_cmd(unsigned char p);

void data_transfer (unsigned char p);

unsigned char keydown(unsigned char key);

void main (void)

{
  unsigned char linia1[]="Temp camera:";
  unsigned char linia2[]="Temp dorita:";
  unsigned int ind;
  unsigned char temp;
  unsigned char tempL;
  unsigned char tempH;
  unsigned char b=0x39;
  unsigned char a=0x31;
  unsigned char temp_set;

//setarea porturilor

P0=0xFF;//am setat P0 ca port de intrare
P1=0xFF;//am setat P1 ca port de intrare
P2=0x00;//am setat P2 ca port de iesire
P3=0x00;//am setat P3 ca port de iesire

  //setarea de comenzi pentru lcd

  lcd_cmd(0x38);//comanda pentru modul opt biti
  lcd_cmd(0x01);//sterge lcd-ul
  lcd_cmd(0x80);//cursorul incepe de la prima linie din stanga
  lcd_cmd(0x0F);

  for (ind=0;ind<12;ind++)
    {
  data_transfer(linia1[ind]);
  }

  //am scris primul mesaj

  lcd_cmd(0xC0);//cursorul merge la a doua linie

  for (ind=0;ind<12;ind++)
    {
  data_transfer(linia2[ind]);
  }/*functie pentru a scrie al doilea mesaj pe a doua linie*/

  while(1)
  {
  CS=0;
  RDC=1;
  WRC=0;
  WRC=1;
  while (INTR==1);

  //finalul unei conversii

  RDC=0;
  delay(5);

  //

  temp=P1;//citim continuu valoarea temperaturii
  temp=temp/0x05;
  tempH=(temp/10)+0x30;//pentru transmiterea primei cifre
  lcd_cmd(0x8C);
  delay(4);
  data_transfer(tempH);
  delay(5);
  tempL=(temp%10)+0x30;//pentru transmiterea celei de a doua cifre
  data_transfer(tempL);
  delay(5);
    data_transfer('o');
  delay(5);
  data_transfer('C');
  delay(5);

  //
 if ((MINUS==0) && (a==0x31) && (b==0x39))
  {}
  else
  if (MINUS==0)
  {
    if (b>=0x31)
    b=b-0x01;
  else
  {
  b=0x39;
  a=a-0x01;
  }
  }
  else
    if (PLUS==0)
  {
    if (b>=0x39)
  {
    b=0x30;
  a=a+0x01;
  }
  else
  b=b+0x01;
  }
  lcd_cmd(0xCC);
  data_transfer(a);
  delay(5);
  data_transfer(b);
  delay(5);
  if (SELECT==0)
  {
  temp_set=(a-0x30)*0x0A+b-0x30;
  }
  if (temp_set>=temp)
  RELEU=0;
  else
  RELEU=1;
  }//end while(1)

}//end void main

void lcd_cmd(unsigned char p)
{
P2=p;
RS=0;
RW=0;
E=1;
delay(5);
E=0;
}

void data_transfer (unsigned char p)
{
P2=p;
RS=1;
RW=0;
E=1;
delay(5);
E=0;
}

unsigned char keydown(unsigned char key)
{
if(PLUS==0 && MINUS==1 && SELECT==1 )
{ key=0; }
if(MINUS==0 && PLUS==1 && SELECT==1 )
{ key=1; }
if(SELECT==0 && PLUS==1 && MINUS==1 )
{ key=2; }
return key;

}//Sfarsit functie keydown

void debounce(void)
{//Intarziere
unsigned int i;
for(i=0;i<=3000;i++);
}//Sfarsit functie debounce

void delay (unsigned int del)//pt ms=5=>18ms
{
unsigned int i,j;
  for (i=0;i<=del;i++)
  for (j=0;j<500;j++);
}
Moderators note : used code tags and removed those hiddious bold characters on every line, removed the MANY empty lines
 

Attachments

Last edited by a moderator:

djsfantasi

Joined Apr 11, 2010
9,163
Please use code tags. The icon, that looks to me like a newspaper, will insert them in your post and then you put your code between the inner brackets.

UPDATE:Thanks, Moderator.
 
Last edited:

spinnaker

Joined Oct 29, 2009
7,830
Hi i'm trying to make a keypad with 3 button, minus,plus and select. When you want a specific temperature, inc/dec and select one which is in variable temp_set. i attached the circuit and the code, and if someone has a solution to this problem don't hesitate.


CODE IN C:

C:
#include <reg51.h>

sbit RS=P3^0;
sbit RW=P3^1;
sbit E=P3^2;
sbit CS=P3^3;
sbit RDC=P3^4;
sbit WRC=P3^5;
sbit INTR=P3^6;
sbit MINUS=P0^0;
sbit PLUS=P0^1;
sbit SELECT=P0^2;
sbit RELEU=P3^7;

void lcd_cmd(unsigned char p);

void data_transfer (unsigned char p);

unsigned char keydown(unsigned char key);

void main (void)

{
  unsigned char linia1[]="Temp camera:";
  unsigned char linia2[]="Temp dorita:";
  unsigned int ind;
  unsigned char temp;
  unsigned char tempL;
  unsigned char tempH;
  unsigned char b=0x39;
  unsigned char a=0x31;
  unsigned char temp_set;

//setarea porturilor

P0=0xFF;//am setat P0 ca port de intrare
P1=0xFF;//am setat P1 ca port de intrare
P2=0x00;//am setat P2 ca port de iesire
P3=0x00;//am setat P3 ca port de iesire

  //setarea de comenzi pentru lcd

  lcd_cmd(0x38);//comanda pentru modul opt biti
  lcd_cmd(0x01);//sterge lcd-ul
  lcd_cmd(0x80);//cursorul incepe de la prima linie din stanga
  lcd_cmd(0x0F);

  for (ind=0;ind<12;ind++)
    {
  data_transfer(linia1[ind]);
  }

  //am scris primul mesaj

  lcd_cmd(0xC0);//cursorul merge la a doua linie

  for (ind=0;ind<12;ind++)
    {
  data_transfer(linia2[ind]);
  }/*functie pentru a scrie al doilea mesaj pe a doua linie*/

  while(1)
  {
  CS=0;
  RDC=1;
  WRC=0;
  WRC=1;
  while (INTR==1);

  //finalul unei conversii

  RDC=0;
  delay(5);

  //

  temp=P1;//citim continuu valoarea temperaturii
  temp=temp/0x05;
  tempH=(temp/10)+0x30;//pentru transmiterea primei cifre
  lcd_cmd(0x8C);
  delay(4);
  data_transfer(tempH);
  delay(5);
  tempL=(temp%10)+0x30;//pentru transmiterea celei de a doua cifre
  data_transfer(tempL);
  delay(5);
    data_transfer('o');
  delay(5);
  data_transfer('C');
  delay(5);

  //
if ((MINUS==0) && (a==0x31) && (b==0x39))
  {}
  else
  if (MINUS==0)
  {
    if (b>=0x31)
    b=b-0x01;
  else
  {
  b=0x39;
  a=a-0x01;
  }
  }
  else
    if (PLUS==0)
  {
    if (b>=0x39)
  {
    b=0x30;
  a=a+0x01;
  }
  else
  b=b+0x01;
  }
  lcd_cmd(0xCC);
  data_transfer(a);
  delay(5);
  data_transfer(b);
  delay(5);
  if (SELECT==0)
  {
  temp_set=(a-0x30)*0x0A+b-0x30;
  }
  if (temp_set>=temp)
  RELEU=0;
  else
  RELEU=1;
  }//end while(1)

}//end void main

void lcd_cmd(unsigned char p)
{
P2=p;
RS=0;
RW=0;
E=1;
delay(5);
E=0;
}

void data_transfer (unsigned char p)
{
P2=p;
RS=1;
RW=0;
E=1;
delay(5);
E=0;
}

unsigned char keydown(unsigned char key)
{
if(PLUS==0 && MINUS==1 && SELECT==1 )
{ key=0; }
if(MINUS==0 && PLUS==1 && SELECT==1 )
{ key=1; }
if(SELECT==0 && PLUS==1 && MINUS==1 )
{ key=2; }
return key;

}//Sfarsit functie keydown

void debounce(void)
{//Intarziere
unsigned int i;
for(i=0;i<=3000;i++);
}//Sfarsit functie debounce

void delay (unsigned int del)//pt ms=5=>18ms
{
unsigned int i,j;
  for (i=0;i<=del;i++)
  for (j=0;j<500;j++);
}
Moderators note : used code tags and removed those hiddious bold characters on every line, removed the MANY empty lines
Do you expect us all to guess at the problem? You have nearly 200 lines of code, commented it what might be Romanian?

You are going to have to put a lot more effort into describing your problem and where the issue is located.

What have you done to troubleshoot the issue? Have you used the debugger?

Also most people don't have Proteus so good luck with that.
 

djsfantasi

Joined Apr 11, 2010
9,163
Yeah, once I saw that all the comments were in some other language. Then, it hit me that the variable names were in another language. Both of these make it impossible to assist. Unless the person is from your country.

Sorry.
 

spinnaker

Joined Oct 29, 2009
7,830
Yeah, once I saw that all the comments were in some other language. Then, it hit me that the variable names were in another language. Both of these make it impossible to assist. Unless the person is from your country.

Sorry.

Well not impossible. But certainly an extremer challenge. And I won't be accepting that kind of challenge unless I am being paid. ;)
 
Top