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 Bài Trong Ngày Vi điều khiển

Trả lời
 
Ðiều Chỉnh Xếp Bài
Old 15-08-2011, 01:35 PM   #1
tdm
Đệ tử 7 túi
 
Tham gia ngày: May 2005
Bài gửi: 258
:
Trích:
Nguyên văn bởi levuphuong View Post
Code:
#include <16F877A.h>
#fuses NOWDT,PUT,XT,NOPROTECT
#use delay(clock=4000000)
#use fast_io(b)
#byte portb=0x06
#byte intcon=0x000B
#bit RB4=portb.4
#bit RB5=portb.5
#bit RBIF=intcon.0 //dinh nghia co ngat RB
#bit RBIE=intcon.3 //dinh nghia bit cho phep ngat RB
int8 a=0;
int8 bien;
const unsigned char ma_ledthuan[]= {
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,
0x81,0x82,0x84,0x88,0x90,0xA0,0xC0,0xC1,
0xC2,0xC4,0xC8,0xD0,0xE0,0xE1,0xE2,0xE4,
0xE8,0xF0,0xF1,0xF2,0xF4,0xF8,0xF9,0xFA,
0xFC,0xFD,0xFE,0xFF,0x00};
const unsigned char ma_lednguoc[]= {
0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,
0x81,0x41,0x21,0x11,0x09,0x05,0x03,0x83,
0x43,0x23,0x13,0x0b,0x07,0x87,0x47,0x27,
0x17,0x0f,0x8f,0x4f,0x2f,0x1f,0x9f,0x5f,
0x3f,0xbf,0x7f,0xFF,0x00};

// Chuong trinh ngat
#int_RB
void ngat_RB()
{
if((RBIF)&&(RBIE))
  {
      //Kiem tra sw1
      {
      if(RB4==1)
        {
        a++ ;
            // thêm delay_ms(10) thì nó không chạy dc
      }
      //Kiem tra sw2
      
  RBIF=0; //Xoa co ngat RB
  }
}
}
// Chuong trinh chinh
void main()
{
set_tris_b(0b11110000);
portb=0b11110000;
enable_interrupts(global);
enable_interrupts(int_RB);
ext_int_edge(H_to_L);
while(true)
  {
  if(a%2==0)
  {
  for(bien=0;bien<=36;bien++)
{
if(a%2==1)
bien=37;
output_d(ma_ledthuan[bien]);
Delay_ms(200);
}
  }
  else
  {
for(bien=0;bien<=36;bien++)
{
if(a%2==0)
bien=37;
output_d(ma_lednguoc[bien]) ;
delay_ms(200) ;

}
  }
}
}
mình đã sửa lại và chạy rồi nhưng khi nhấn 5 cái có 1 cái hok ăn.xem trên diễn đàn th2i là do hiện tuong rung phím.Mình thử thêm delay vào ben trong ngắt .sau dò phím thì nó lại bi warning và code hok chạy luôn
Nó báo sẽ không ngắt khi chay hàm delay_ms
Các bác giúp em với
vẫn chạy bt,mô phỏng proteus không cần chống rung .nhấn phím thì giữ một chút nhé .

Code:
#include <16F877A.h>
#fuses NOWDT,PUT,XT,NOPROTECT
#use delay(clock=4000000)
#use fast_io(b)
#byte portb=0x06
#byte intcon=0x000B
#bit RB4=portb.4
#bit RB5=portb.5
#bit RBIF=intcon.0 //dinh nghia co ngat RB
#bit RBIE=intcon.3 //dinh nghia bit cho phep ngat RB
int8 a=0;
int8 bien;
const unsigned char ma_ledthuan[]= {
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,
0x81,0x82,0x84,0x88,0x90,0xA0,0xC0,0xC1,
0xC2,0xC4,0xC8,0xD0,0xE0,0xE1,0xE2,0xE4,
0xE8,0xF0,0xF1,0xF2,0xF4,0xF8,0xF9,0xFA,
0xFC,0xFD,0xFE,0xFF,0x00};
const unsigned char ma_lednguoc[]= {
0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,
0x81,0x41,0x21,0x11,0x09,0x05,0x03,0x83,
0x43,0x23,0x13,0x0b,0x07,0x87,0x47,0x27,
0x17,0x0f,0x8f,0x4f,0x2f,0x1f,0x9f,0x5f,
0x3f,0xbf,0x7f,0xFF,0x00};

// Chuong trinh ngat
#int_RB
void ngat_RB()
{
if((RBIF)&&(RBIE))
  {

      if(RB4==1)
        {
        
        a++ ;
      delay_ms(10) ;//thi? no? không cha?y dc
      }
}
}
// Chuong trinh chinh
void main()
{
set_tris_b(0b11110000);
portb=0b11110000;
enable_interrupts(global);
enable_interrupts(int_RB);
ext_int_edge(H_to_L);
while(true)
  {
  if(a%2==0)
  {
  for(bien=0;bien<=36;bien++)
{
if(a%2==1)
bien=37;
output_d(ma_ledthuan[bien]);
Delay_ms(200);
}
  }
  else
  {
for(bien=0;bien<=36;bien++)
{
if(a%2==0)
bien=37;
output_d(ma_lednguoc[bien]) ;
delay_ms(200) ;

}
  }
}
}
__________________
viết chương trình cho vdk chạy ổn định là cả một vấn đề.
tdm vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Trả lờ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à 02:02 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