View Single Post
Old 08-01-2011, 09:17 AM   #7
quangvanvo
Đệ tử 1 túi
 
Tham gia ngày: Jan 2011
Bài gửi: 18
:
giúp em với mấy anh chị ơi

em mới viết code lần đầu nên nó báo lỗi mà em thật sự không biết tại sao
đây là đoạn code ma có thể dung thẳng TRISx, POTRx để viết code
#include<16F877A.h>
#include<def_877a.h>
#fuses NOWDT,PUT,HS,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use fast_io(b)
int8 sck,slx,bienxoay,bienluu,giatri;
main()
{
trisb=0;
while(true)
{
sck=8;
bienluu=0;
portb=0;
delay_ms(100);
while(sck>0)
{
bienxoay=1;
slx=sck;
while(slx>0)
{
giatri=bienluu|bienxoay;
portb=giatri;
delay_ms(100);
bienxoay=bienxoay<<1;
slx--;
}
bienluu=giatri;
sck--;
}
}
}
nhưng đoạn code này thì em dùng thẳng trisx, portx thì không được nhung dùng lệnh set_tris_x(gia tri), set_port_x(gia tri) thi được em nghi đó là do khai báo lúc đầu
#include "E:\PIC\main.h"
#include <16f877a.h>
#include <def_877a.h>
#device *=16 ADC=8
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)

void main()
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

// TODO: USER CODE!!
TRISB = 0x00; // Tat ca PORTB deu la cong xuat du lieu
PORTB = 0xFF; // Tat het cac LED
While(1)
{
PORTB = 0; // Cho các LED sáng
delay_ms(250); // T.o th.i gian tr. 250ms
PORTB = 0xFF;
delay_ms(250);
}

}
quangvanvo vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn