PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Các ngôn ngữ lập trình khác (CCS C, HT PIC,...)

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Tìm Kiếm Bài Trong Ngày Ðánh Dấu Ðã Ðọc Vi điều khiển

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 14-01-2008, 09:06 AM   #10
Jerry
Đệ tử 5 túi
 
Jerry's Avatar
 
Tham gia ngày: Sep 2006
Bài gửi: 100
:
Đầu tiên là thử quét phím bằng timer0 (chưa thử bấm nhanh hay bấm lấu)
Code:
#include <16F877A.h>
#include <def_877a.h>
#device *=16 adc=10
#FUSES NOWDT, XT, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=4000000)
#use fast_io (b)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9)

#define OK PIN_B6
#define Cancel PIN_B7

#define OK_PRESSED  !input(OK)

#include <lcd_lib_4bit.c>

   int8 count;
   char phim;
   int8 isr_count;

#int_TIMER0
void interrupt_timer0()
{
   if(OK_PRESSED)
   {
      isr_count++;
      if(isr_count==81)
      {
         isr_count==0;
         disable_interrupts(GLOBAL);
         disable_interrupts(INT_TIMER0);
      }
   }
   else
   {
      disable_interrupts(GLOBAL);
      disable_interrupts(INT_TIMER0);
   }
}

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

void main(void)
{
   output_b(0xC0);
   set_tris_a(0xC0);
   set_tris_b(0xC1);
   port_b_pullups (TRUE);

   LCD_init();
   delay_ms(500);
   LCD_putcmd(0x80);
   Printf(LCD_putchar,"Hi ev'body");   //Hien thi man hinh 1
   LCD_putcmd(0xC0);
   Printf(LCD_putchar,"Khoi tao...");

   if(OK_PRESSED)
   {           //enable timer0
      enable_interrupts(INT_TIMER0);
      enable_interrupts(GLOBAL);
   }
   if(isr_count==0)
   {
      LCD_putcmd(0x01);    //xoa man hinh
      LCD_putcmd(0x80);
      Printf(LCD_putchar,"Enter Pressed");  //Hien thi man hinh 2
   }
}
Nhưng mà chưa được. Nạp chương trình, cắm điện vào nó hiện luôn Enter Pressed, dù thực tế chưa bấm phát nào. Các cao thủ đâu hết cả rồi, trả lời tui đi chứ.
__________________
Do more than exist, LIVE
Jerry vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 

Ðiều Chỉnh
Xếp Bài

Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 06:24 PM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam