PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   Các ngôn ngữ lập trình khác (CCS C, HT PIC,...) (http://www.picvietnam.com/forum/forumdisplay.php?f=12)
-   -   Hàm delay trong XC8 (http://www.picvietnam.com/forum/showthread.php?t=33833)

longdv 12-10-2014 12:21 PM

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 13-10-2014 11:46 AM

em đã giải quyết được. Thực ra nó đang bị vấn đề ở chế độ #pragma config LVP = ON , Tắt nó đi là chạy bình thường.
nhưng vẫn chưa hiểu kỹ nó lắm. :D


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

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam