Autor Tema: quien me ayuda con esto  (Leído 2427 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado nordestenica

  • PIC16
  • ***
  • Mensajes: 215
quien me ayuda con esto
« en: 10 de Abril de 2004, 04:38:00 »
ola a todos estoy intentando entrar en el c y va pero mal

la question es que e cojido unos codigos e los e estado estudiando e me parecen interensantes e e echo algunas pruebas e e chegado a esto un menu en una lcd que te da un beep cada vez que pulsas un boton e vaz a esse otro menu en esse otro menu tienes la opcion de up dow lo que quiero acer es que cada vez que se pulse un boton en la pantalha lcd muestre por exemplo 1 si vuelves a pulsar esse mismo boton en la pantalha lcd te muestre 2 lo e intentado todo e nada


otra perguntinta como se puede acer que en un pin de un pic cada vez que pulsas un boton esse pin vaya aumentando su salida exemplo

si pulsas el boton una vez en el pin b1 tendras 0,5V si pulsas otras vez esse mismo boton en el pin te subira de 0,5V a 1V e assi en adelantre asta chegar a los 5V

aqui les dejo el codigo

el codigo es interesante e no no es de mi autoria yo solo lo coji e le ices los cambios pero es interesante mirenlo e pruebenlo


#case
#include <16F877.H>

#device *=16
#device ICD=TRUE
#device adc=10

#fuses NOWDT,HS, PUT, NOPROTECT, BROWNOUT, NOLVP
//#fuses XT, NOPROTECT, PUT, NOWDT, BROWNOUT, NOLVP, NOCPD, NOWRT
#use delay ( clock=4000000 )
#use standard_io ( A )
#use standard_io ( B )
#use standard_io ( C )


//***************************LCD NAO MEXER**************************************
/* LCD STUFF */
#define LCD_D0  PIN_D2
#define LCD_D1  PIN_D3
#define LCD_D2  PIN_D4
#define LCD_D3  PIN_D5
#define LCD_EN  PIN_D1
#define LCD_RS  PIN_D0
#define LINHA_1  0
#define LINHA_2  0x40
#define CLEAR_DISP  0x01
void LCD_Init ( void );
void LCD_SetPosition ( unsigned int cX );
void LCD_PutChar ( unsigned int cX );
void LCD_PutCmd ( unsigned int cX );
void LCD_PulseEnable ( void );
void LCD_SetData ( unsigned int cX );
//**************************+FIN LCD********************************************
void BUTON_1 ( void );
void BUTON_2 ( void );
void BUTON_3 ( void );


static char cEnlargeTime, cMenu;

#define PULSE_1      PIN_C0
#define PULSE_2      PIN_C1
#define PULSE_3      PIN_C2

#define DEBOUNCE_DELAY      20

void BAIXA ( void );
void MEDIA ( void );
void ALTA ( void );
void VOLT_5 ( void );
void VOLT_12 ( void );
void VOLT_15 ( void );
void BEEP ( void );
void BAIXA_MAIS ( void );
void BAIXA_MENOS ( void );
void BUTON_1 ( void );
void BUTON_2 ( void );
void BUTON_3 ( void );



//*********************INICIO***************************************************
void main ( void )
{
   char cX;
   LCD_Init();
   LCD_PutCmd ( CLEAR_DISP );
   LCD_PutCmd ( CLEAR_DISP );
   LCD_SetPosition (LINHA_1 );
   printf ( LCD_PutChar, " **MAXI POWER** " );
   delay_ms(500);
   LCD_SetPosition ( LINHA_2 );
   printf ( LCD_PutChar, "  Manuel Xastre  " );
   delay_ms(2000);

   while ( TRUE )
   {
      char cX;
      LCD_PutCmd ( CLEAR_DISP );
      LCD_SetPosition ( LINHA_1 );
      printf ( LCD_PutChar, "Select...  " );
      delay_ms (50);
      LCD_SetPosition ( LINHA_2 );
      printf ( LCD_PutChar, "baixa media alta" );
      delay_ms ( 50);
      while ( TRUE )
      {
         if ( input ( PULSE_1 ) == 0 )
         {
            BEEP();
            BAIXA();
            break;
         }
         if ( input ( PULSE_2 ) == 0 )
         {
            BEEP();
            MEDIA();
            break;
         }
         if ( input ( PULSE_3 ) == 0 )
         {
            BEEP();
            ALTA();
            break;
            delay_ms(100);
         }
      }
   }
}
//***************************BAIXA**********************************************


void BAIXA ( void )
{

   LCD_PutCmd ( CLEAR_DISP );
   LCD_SetPosition ( LINHA_1 );
   printf ( LCD_PutChar, "Escolheu Baixa.." );
   delay_ms (50);
   LCD_SetPosition ( LINHA_2 );
   printf ( LCD_PutChar, "             Bak" );
   delay_ms ( 50);
  while ( TRUE )
      {

         if ( input ( PULSE_1 ) == 0 )
         {
            BEEP();

   
            break;
                     }

 //----------------------------------------------------------------------------

 //------------------------------------------------------------------------------



         }
         if ( input ( PULSE_3 ) == 0 )
         {
            BEEP();
            break;
            delay_ms(100);

         }
      }


//************************MEDIA*****************************************

void MEDIA ( void )
{

   LCD_PutCmd ( CLEAR_DISP );
   LCD_SetPosition ( LINHA_1 );
   printf ( LCD_PutChar, "Escolheu Media.." );
   delay_ms (50);
   LCD_SetPosition ( LINHA_2 );
   printf ( LCD_PutChar, "             Bak" );
   delay_ms ( 50);
   while ( TRUE )
      {

         if ( input ( PULSE_3 ) == 0 )
         {
            BEEP();
            break;



            delay_ms(100);
         }
      }
   }




//***********************ALTA**************************************************

void ALTA ( void )
{

   LCD_PutCmd ( CLEAR_DISP );
   LCD_SetPosition ( LINHA_1 );
   printf ( LCD_PutChar, "Escolheu Alta.." );
   delay_ms (50);
   LCD_SetPosition ( LINHA_2 );
   printf ( LCD_PutChar, "            Bak" );
   delay_ms ( 50);
   while ( TRUE )
      {

         if ( input ( PULSE_3 ) == 0 )
         {
            BEEP();
            break;



            delay_ms(100);
         }
      }
   }



//*********************PULSO SAIDA ALTA*****************************************

void BAIXA_MAIS ( void )
{
   output_high (PIN_B0 );
   delay_ms ( 900 );
   output_low ( PIN_B0 );
   delay_ms ( 900 );
}
//**************************BEEP INFORMA***************************************+
void BEEP ( void )
{
   output_high ( PIN_D7 );
   delay_ms ( 500 );
   output_low ( PIN_D7 );
   delay_ms ( 500 );
}
//****************************+RUTINA LCD NAO MEXER*****************************
void LCD_Init ( void )
{
   LCD_SetData ( 0x00 );
   delay_ms ( 200 );       /* wait enough time after Vdd rise */
   output_low ( LCD_RS );
   LCD_SetData ( 0x03 );   /* init with specific nibbles to start 4-bit mode */
   LCD_PulseEnable();
   LCD_PulseEnable();
   LCD_PulseEnable();
   LCD_SetData ( 0x02 );   /* set 4-bit interface */
   LCD_PulseEnable();      /* send dual nibbles hereafter, MSN first */
   LCD_PutCmd ( 0x2C );    /* function set (all lines, 5x7 characters) */
   LCD_PutCmd ( 0x0C );    /* display ON, cursor off, no blink */
   LCD_PutCmd ( 0x01 );    /* clear display */
   LCD_PutCmd ( 0x06 );    /* entry mode set, increment */
}

void LCD_SetPosition ( unsigned int cX )
{
   /* this subroutine works specifically for 4-bit Port A */
   LCD_SetData ( swap ( cX ) | 0x08 );
   LCD_PulseEnable();
   LCD_SetData ( swap ( cX ) );
   LCD_PulseEnable();
}

void LCD_PutChar ( unsigned int cX )
{
   /* this subroutine works specifically for 4-bit Port A */
   output_high ( LCD_RS );
   LCD_SetData ( swap ( cX ) );     /* send high nibble */
   LCD_PulseEnable();
   LCD_SetData ( swap ( cX ) );     /* send low nibble */
   LCD_PulseEnable();
   output_low ( LCD_RS );
}

void LCD_PutCmd ( unsigned int cX )
{
   /* this subroutine works specifically for 4-bit Port A */
   LCD_SetData ( swap ( cX ) );     /* send high nibble */
   LCD_PulseEnable();
   LCD_SetData ( swap ( cX ) );     /* send low nibble */
   LCD_PulseEnable();
}

void LCD_PulseEnable ( void )
{
   output_high ( LCD_EN );
   delay_us ( 10 );
   output_low ( LCD_EN );
   delay_ms ( 5 );
}

void LCD_SetData ( unsigned int cX )
{
   output_bit ( LCD_D0, cX & 0x01 );
   output_bit ( LCD_D1, cX & 0x02 );
   output_bit ( LCD_D2, cX & 0x04 );
   output_bit ( LCD_D3, cX & 0x08 );
}




 

anything