GIAO TIẾP LCD NÚT NHẤN VỚI VB 6.0 PIC16F877A

9:18:00 AM
Chào các bạn hôm này mình sẽ chia sẽ với các bạn 1 project cũng khá hay về phần mềm VB 6.0 với LCD và nút nhấn trong bài đăng trước và bài đăng này mình sẽ tích hợp 2 cái lại nha !
- Đây là ảnh mô phỏng protues.


- Đây là code cho PIC.
#include <16f877A.h>
#use delay(clock=20000000)
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use rs232(baud=9600,parity=n,xmit=PIN_C6,rcv=PIN_C7)
#include <lcd1.c> 
char ch,string1[16],string2[16];
int  state,j=0,k=0,temp1=0,temp2=0; 
int8 a;
#define nut1 PIN_B0
#define nut2 PIN_B1
#define nut3 PIN_B2
#define nut4 PIN_B3
#define nut5 PIN_B4
#define nut6 PIN_B5
#define nut7 PIN_B6
#define nut8 PIN_B7
#int_RDA
void Receive_isr()

   ch=getc();
   if(ch=='1')
   a=1;
   if(ch=='2')
   a=2;
   if(ch=='3')
   a=3;
   if(ch=='4')
   a=4;
   if(ch=='A')
   a=5;
   if(ch=='B')
   a=6;
   if(ch=='C')
   a=7;
   if(ch=='D')
   a=8; 
   if(ch=='S')
   {
   output_high(pin_A0) ;
   output_high(pin_A1) ;
   output_high(pin_A2) ;
   output_high(pin_A3) ;
   }
   if(ch=='T')
  {
   output_low(pin_A0) ;
   output_low(pin_A1) ;
   output_low(pin_A2) ;
   output_low(pin_A3) ;
  }
   if(ch=='`')
   state=1;
   if(ch=='~')
   state=2;
if(state==1)
    {
      if(ch!='`'&&ch!='{'&&ch!='}')
       {
          string1[j]=ch;
          j++;
         temp1=j;
      }
    }
if(state==2)
    {
       if(ch!='~'&&ch!='{'&&ch!='}')
       {
          string2[k]=ch;
          k++;
          temp2=k;
       }
    }
if(ch=='}')
    {
      lcd_gotoxy(1,1);
      for(j=0;j<temp1;j++)
         {
         lcd_putc(string1[j]);
         }
      lcd_gotoxy(1,2);
      for(k=0;k<temp2;k++)
         {
         lcd_putc(string2[k]);
         }
    } 
  if(ch=='{')
    {
      lcd_putc('\f');
      k=0;
      j=0;
      temp1=0;
      temp2=0;
    }
}
void banphim()

if(input(PIN_B0)==0)
a=1;
if(input(PIN_B1)==0)
a=2;
if(input(PIN_B2)==0)
a=3;
if(input(PIN_B3)==0)
a=4;
if(input(PIN_B4)==0)
a=5;
if(input(PIN_B5)==0)
a=6;
if(input(PIN_B6)==0)
a=7;
if(input(PIN_B7)==0)
a=8;
}  
void main()
{
  ENABLE_INTERRUPTS(INT_RDA);                                  
  enable_interrupts(GLOBAL);
  SET_TRIS_B( 0xff );
   lcd_init();
   int j;
        lcd_gotoxy(1,1);
   printf(lcd_putc," MR.TOAN " );
      lcd_gotoxy(1,2);
   printf(lcd_putc,"01656053313");
for(j=0;j<15;j++)
{
      lcd_send_byte(0,0x1c);
      delay_ms(10);

lcd_putc('\f');
lcd_gotoxy(1,1);
   printf(lcd_putc,"wait..... " );
   delay_ms(300);
   lcd_putc('\f');
while(1)
{
banphim();
if(a==1)
{
putc('1');
for(;;)
{
banphim();
output_high(pin_A0);
if( a==2 || a==3 || a==4 || a==5 || a==6 || a==7 || a==8)
break;
}
}
if(a==2)
{
putc('2');
for(;;)
{
banphim();
set_tris_a(0);
output_high(pin_A1);
if( a==1 || a==3 || a==4 || a==5 || a==6 || a==7 || a==8)
break;
}
}
if(a==3)
{
putc('3');
for(;;)
{
banphim();
set_tris_a(0);
output_high(pin_A2);
if(a==1 || a==2 || a==4 || a==5 || a==6 || a==7 || a==8)
break;
}
}
if(a==4)
{
putc('4');
for(;;)
{
banphim();
set_tris_a(0);
output_high(pin_A3);
if( a==1 || a==2 || a==3  || a==5 || a==6 || a==7 || a==8)
break;
}
}
if(a==5)
{
putc('A');
for(;;)
{
banphim();
set_tris_a(0);
output_low(pin_A0);
if( a==1 || a==2 || a==3 || a==4 || a==6 || a==7 || a==8)
break;
}
}
if(a==6)
{
putc('B');
for(;;)
{
banphim();
set_tris_a(0);
output_low(pin_A1);
if( a==1 || a==2 || a==3 || a==4 || a==5  || a==7 || a==8)
break;
}
}
if(a==7)
{
putc('C');
for(;;)
{
banphim();
set_tris_a(0);
output_low(pin_A2);
if(a==1 || a==2 || a==3 || a==4 || a==5 || a==6  || a==8)
break;
}
}
if(a==8)
{
putc('D');
for(;;)
{
banphim();
set_tris_a(0);
output_low(pin_A3);
if(a==1 || a==2 || a==3 || a==4 || a==5 || a==6 || a==7 )
break;
}
}
}
}
Download project về để xem code đầy đủ nha !
- Link download project Click here

Share this

Related Posts

Previous
Next Post »