quet ban phim

/*

Ngay:                6/12/2010

De tai:              Ket noi ban phim 12 phim voi VDK

Ten file:            Code43M2.c

Phan cung su dung:   PIC 18F452

                     Ban phim 12 phim

                     LCD 16x2

*/

#include<18f452.h>

#use delay(clock=20000000)

#include<def_18f452.h>

#include<lcd_4bit.c>

#bit  cot1=portb.0

#bit  cot2=portb.1

#bit  cot3=portb.2

#bit  hang1=portb.4

#bit  hang2=portb.5

#bit  hang3=portb.6

#bit  hang4=portb.7

int8  const tit0[]={"*BAI THAO LUAN*"};

int8  const tit1[]={"-Nhom 6 - 43M2-"};

int8  const tit2[]={"PRESSED KEY : "};

int8  const tit3[]={"SCANING KEYBOAD"};

int8 i;

void write_line1(void)

{

   lcd_putcmd(clear_scr);

   lcd_putcmd(line_1);

   i=0;

   while(tit2[i]!=0)

   {

      lcd_putchar(tit2[i]);

      i++;

   }

}

void  write_line2(void)

{

   lcd_putcmd(line_2);

   i=0;

   while(tit3[i]!=0)

   {

      lcd_putchar(tit3[i]);

      i++;

   }

}

#int_RB // Chuong trinh ngat Port B

void  RB_isr(void)

{

  if(cot1==1)

  {

      if(hang1==1)

      {

         //hien thi phim 1

         write_line1();

         lcd_putchar('1');// Hien thi ra LCD so 1

         write_line2();

      }

      else  if(hang2==1)

            {

               //hien thi phim 4

               write_line1();

               lcd_putchar('4');// Hien thi ra LCD so 4

               write_line2();

            }

            else  if(hang3==1)

                  {

                     //hien thi phim 7

                     write_line1();

                     lcd_putchar('7');// Hien thi ra LCD so 7

                     write_line2();

                 }

                  else  if(hang4==1)

                        {

                           //hien thi phim *

                           write_line1();

                           lcd_putchar('*');// Hien thi ra LCD ky tu *

                           write_line2();

                        }

  }

  else if(cot2==1)

       {  

         if(hang1==1)

         {

            //hien thi phim 2

            write_line1();

            lcd_putchar('2');// Hien thi ra LCD so 2

            write_line2();

         }

         else  if(hang2==1)

               {

                //hien thi phim 5

                write_line1();

                lcd_putchar('5');// Hien thi ra LCD so 5

                write_line2();

               }

               else  if(hang3==1)

                     {

                        //hien thi phim 8

                        write_line1();

                        lcd_putchar('8');// Hien thi ra LCD so 8

                        write_line2();

                     }

                     else  if(hang4==1)

                           {

                               //hien thi phim 0

                              write_line1();

                              lcd_putchar('0');// Hien thi ra LCD so 0

                              write_line2();

                           }

       }

         else if(cot3==1)

                  if(hang1==1)

                  {

                     //hien thi phim 3

                     write_line1();

                     lcd_putchar('3');// Hien thi ra LCD so 3

                     write_line2();

                  }

                  else  if(hang2==1)

                        {

                           //hien thi phim 6

                           write_line1();

                           lcd_putchar('6');// Hien thi ra LCD so 6

                           write_line2();

                        }

                        else if(hang3==1)

                              {

                                 //hien thi phim 9

                                 write_line1();

                                 lcd_putchar('9');// Hien thi ra LCD so 9

                                 write_line2();

                              }

                              else if(hang4==1)

                                    {

                                       //hien thi phim #

                                       write_line1();

                                       lcd_putchar('#');// Hien thi ra LCD ky tu #

                                       write_line2();

                                    }

}

void main()

{

   //lcd_init();

   setup_adc_ports(NO_ANALOGS);

   setup_adc(ADC_OFF);

   setup_psp(PSP_DISABLED);

   setup_spi(SPI_SS_DISABLED);

   setup_wdt(WDT_OFF);

   setup_timer_0(RTCC_INTERNAL);

   setup_timer_1(T1_DISABLED);

   setup_timer_2(T2_DISABLED,0,1);

   lcd_init();

   enable_interrupts(INT_RB);

  // enable_interrupts(GLOBAL);

//Setup_Oscillator parameter not selected from Intr Oscillotar Config tab

   // TODO: USER CODE!!

   trisb=0xf0;

   while(tit0[i]!=0)

   {

      lcd_putchar(tit0[i]);

      i++;

      delay_ms(70);      

   }

   lcd_putcmd(line_2);

   i=0;

   while(tit1[i]!=0)

   {

      lcd_putchar(tit1[i]);

      i++;

      delay_ms(70);      

   }

   delay_ms(2000);

   lcd_putcmd(clear_scr);

   write_line2();

   enable_interrupts(GLOBAL);

   while(1)

   {

      //quet cot

      cot3=0;

      cot1=1;

      delay_ms(10);

      cot1=0;

      cot2=1;

      delay_ms(10);

      cot2=0;

      cot3=1;

      delay_ms(10);

   }

}

Bạn đang đọc truyện trên: AzTruyen.Top