View Full Version : PIC 12F629 - Đọc nút nhấn
boylikerock197
23-03-2011, 03:09 PM
Em viết chương trình cho con 12F629, nối đèn led với chân số 5, đầu kia của đèn led lên nguồn. Bây giờ em cho chân số 5 xuống 0 để đèn led sáng, viết chương trình không báo lỗi nhưng mô phỏng trong proteus thì không chạy. Nếu viết chương trìng cho các chân khác thì chạy bình thường, em không hiểu vì sao, nhờ các bác giúp đỡ
#include <12F629.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOCPD //No EE protection
#FUSES NOPROTECT //Code not protected from reading
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPUT //No Power Up Timer
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BANDGAP_HIGH
#FUSES RESERVED //Used to set the reserved FUSE bits
#use delay(clock=4000000)
void main()
{
while(1)
{
output_low(PIN_A3);
}
}
Em viết chương trình cho con 12F629, nối đèn led với chân số 5, đầu kia của đèn led lên nguồn. Bây giờ em cho chân số 5 xuống 0 để đèn led sáng, viết chương trình không báo lỗi nhưng mô phỏng trong proteus thì không chạy. Nếu viết chương trìng cho các chân khác thì chạy bình thường, em không hiểu vì sao, nhờ các bác giúp đỡ
#include <12F629.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOCPD //No EE protection
#FUSES NOPROTECT //Code not protected from reading
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPUT //No Power Up Timer
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BANDGAP_HIGH
#FUSES RESERVED //Used to set the reserved FUSE bits
#use delay(clock=4000000)
void main()
{
while(1)
{
output_low(PIN_A3);
}
}
bạn thiếu lệnh: set_tris_a(0x00)//portA là output
PIN_A3 chỉ có thể làm chân input(khi sử dụng cấu hình #FUSES NOMCLR)
trích data sheet:
GPIO is an 6-bit wide, bi-directional port. The corre-
sponding data direction register is TRISIO. Setting a
TRISIO bit (= 1) will make the corresponding GPIO pin
an input (i.e., put the corresponding output driver in a
Hi-impedance mode). Clearing a TRISIO bit (= 0) will
make the corresponding GPIO pin an output (i.e., put
the contents of the output latch on the selected pin).
-------------------------------------------------
The exception is GP3, which is input only and its
------------------------------------------------
TRISIO bit will always read as ‘1’. Example 3-1 shows
how to initialize GPIO.
arm_cortex01
03-04-2011, 06:36 PM
GPIO is an 6-bit wide, bi-directional port. The corre-
sponding data direction register is TRISIO. Setting a
TRISIO bit (= 1) will make the corresponding GPIO pin
an input (i.e., put the corresponding output driver in a
Hi-impedance mode). Clearing a TRISIO bit (= 0) will
make the corresponding GPIO pin an output (i.e., put
the contents of the output latch on the selected pin).
-------------------------------------------------
The exception is GP3, which is input only and its
------------------------------------------------
TRISIO bit will always read as ‘1’. Example 3-1 shows
how to initialize GPIO.
__________________
--> chưa hiểu lắm.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.