![]() |
|
|
#1 |
|
Nhập môn đệ tử
Tham gia ngày: Nov 2008
Bài gửi: 5
: |
chương trình này em viết trên MikroC 8.2
Code:
void main() {
PORTA = 0; // Initialize PORTA
TRISA = 0; // Configure PORTA as output
PORTB = 0; // Initialize PORTB
TRISB = 0; // Configure PORTB as output
PORTC = 0; // Initialize PORTC
TRISC = 0; // Configure PORTC as output
PORTD = 0; // Initialize PORTD
TRISD = 0; // Configure PORTD as output
while(1) {
PORTA = ~PORTA; // toggle PORTA
Delay_ms(1000); // one second delay
PORTB = ~PORTB; // toggle PORTB
Delay_ms(1000); // one second delay
PORTC = ~PORTC; // toggle PORTC
Delay_ms(1000); // one second delay
PORTD = ~PORTD; // toggle PORTD
Delay_ms(1000); // one second delay
}
}
|
|
|
|
|
|
#2 |
|
Đệ tử 3 túi
Tham gia ngày: Oct 2006
Bài gửi: 46
: |
Bạn chưa config cho portA, ko biết bạn dùng pic gì, bạn phải mắc thêm một điện trở kéo lên ở ra4. Chương trình của bạn mình thừ dùng cho pic16f877a sửa lại như sau:
Code:
void main() {
ADCON1=0x06; //config porta thanh digital in/out
PORTA = 0; // Initialize PORTA
TRISA = 0; // Configure PORTA as output
PORTB = 0; // Initialize PORTB
TRISB = 0; // Configure PORTB as output
PORTC = 0; // Initialize PORTC
TRISC = 0; // Configure PORTC as output
PORTD = 0; // Initialize PORTD
TRISD = 0; // Configure PORTD as output
while(1) {
PORTA = ~PORTA; // toggle PORTA
Delay_ms(1000); // one second delay
PORTB = ~PORTB; // toggle PORTB
Delay_ms(1000); // one second delay
PORTC = ~PORTC; // toggle PORTC
Delay_ms(1000); // one second delay
PORTD = ~PORTD; // toggle PORTD
Delay_ms(1000); // one second delay
}
}
__________________
http://www.hieunghia.info Lướt web thoải mái với USB3G của Viettel http://www.hieunghia.info/tin-cong-n...3g-vietel.html ----------------------------------------------------------------------------------- Một chút giận,hai chút tham,lận đận cả đời ri cũng khổ. Trăm điều lành,ngàn điều nhịn,thong dong tấc dạ rứa mà vui |
|
|
|
|
|
#3 |
|
Nhập môn đệ tử
Tham gia ngày: Nov 2008
Bài gửi: 5
: |
cám ơn anh,em dùng con 877a,nó chạy tốt rồi.
|
|
|
|
|
|
#4 |
|
Nhập môn đệ tử
Tham gia ngày: Nov 2008
Bài gửi: 5
: |
Code:
#include "Display_utils.h"
unsigned short i;
void main() {
ADCON1=0x06;
PORTA = 0;
TRISA = 0;
PORTD = 0;
TRISD = 0;
do {
for (i = 0; i <= 9; i++) {
PORTD = ~mask(i); // bring appropriate value to PORTD
PORTA = 1; // turn on appropriate 7seg. display
Delay_ms(1000);
}
} while (1); //endless loop
}
thay đổi nội dung bởi: bocon1903, 22-12-2009 lúc 10:24 PM. |
|
|
|
![]() |
|
|