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 12-10-2014, 12:21 PM   #1
longdv
Đệ tử 2 túi
 
Tham gia ngày: Oct 2009
Bài gửi: 26
:
Angry Hàm delay trong XC8

Mình đang thử thử làm việc với MPLABX và XC8 và con 16f887, nhưng mới mở đầu đã gặp trục trặc, cụ thể là mình không thể sử dụng cái hàm __delayms(); trong thư viện xc.h của nó.
code mình như sau:

#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON // RE3/MCLR pin function select bit (RE3/MCLR pin function is MCLR)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown Out Reset Selection bits (BOR enabled)
#pragma config IESO = ON // Internal External Switchover bit (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)
#pragma config LVP = ON // Low Voltage Programming Enable bit (RB3/PGM pin has PGM function, low voltage programming enabled)

// CONFIG2
#pragma config BOR4V = BOR40V // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
#pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off)

#include <stdio.h>
#include <stdlib.h>
#include <pic16f887.h>
#include <xc.h>
#define _XTAL_FREQ 20000000

int main(int argc, char** argv) {
TRISC=0x00;
PORTC=0x00;

TRISE=0xFF;
while(1){

__delay_ms(100);
PORTC=0x00;
__delay_ms(100);
PORTC=0xFF;
};
return (EXIT_SUCCESS);
}
trên Protues thì chạy đúng nhưng trên mạch thì chỉ xuất ra PORTC=0x00 thôi, không chớp tắt được.
thêm một cái nữa là khi em đụng tay vào võ laptop thì đèn tắt hoặc sáng yếu lại, như bị sụt áp vậy (vì nguồn em lấy từ latop), em đã thử nạp bằng một chương trình khác viết bằng CCS thì không bị hiện tượng này, mọi thứ chạy OK.
Anh em nào giúp giùm mình với.
longdv 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à 03:22 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