او هذا كود ايضا يعمل
كود:
void main()
{
trisa=0;
trisb=0;
trisc=0;
trisd=0;
latb=0;
while(1)
{
portb=0;
porta=0;
portc=0;
portd=0;
delay_ms(100);
porta=0xff;
portb=0xff;
portc=0xff;
portd=0xff;
delay_ms(100);
}
}
لكن يااخي لاتنسى هناك فقره مهمه هي تحديد طبيعه بورت هي هل يتعامل مع digital او anloge
لاحظ هذه لاحظه من منول
Note: On a Power-on Reset, RA5 and RA3:RA0
are configured as analog inputs and read
as ‘0’. RA4 is configured as a digital input.
او
========================================
Note: On a Power-on Reset, RB4:RB0 are
configured as analog inputs by default and
read as ‘0’; RB7:RB5 are configured as
digital inputs.
By programming the Configuration bit,
PBADEN (CONFIG3H<1>), RB4:RB0 will
alternatively be configured as digital inputs
on POR.
============================================
Note: On a Power-on Reset, these pins, except
RC4 and RC5, are configured as digital
inputs. To use pins RC4 and RC5 as digital
inputs, the USB module must be disabled
(UCON<3> = 0) and the on-chip
USB transceiver must be disabled
(UCFG<3> = 1).
================================================
Note: On a Power-on Reset, RE3 is enabled as
a digital input only if Master Clear
functionality is disabled.
==============================================
نصيحه دائما اذهب في منول الى فقره I/O port
ثم اختار بورت بورت ولاحظ فقره تعريف بورت موجوده في كل منول مثلا راح شوف هاي عباره
INITIALIZING PORTA وبداخلها مجموعه الاوامر روح الى الاوامر تخص الادخالات او تخص بورت مثلا
MOVLW 0Fh ; Configure A/D
MOVWF ADCON1 ; for digital inputs
معناه هكذا خلي adcon1 =0x0f حتى يصبح بورت digital
او انك شوف اي سجل يتعامل هذا بورت هنا هو adcon1
بسيطه في منول ابحث عن هذا سجل للسهوله اضغط ctrl+f راح يطلع مستطيل صغير اضع فيه كلمه التي تريد البحث عنها واضغط على enter بخفه الى ان يطلع لك سجل وسجل بسيط فيه 8 بتات شوف كل بت شنو مهمته
لو تلاحظ adcon1 خله ب 0f راح شوف ان لو خليت اول اربع بتات كلها 1 يصبح بورت كله ديجتل واذا جعلته اول اربع بتات كلها 0 يصبح بورت كله anloage
ضروري اخي تعرف هذه معلومات حتى تستطيع فهم سجل ودائما ابحث عن الذي تحتاجه اكيد راح يقود الى سجل وفيه 8 بتات لو فهمت مره او مرتين كيفه تقرا سجل صدقني سيسهل عليك كثير في تعامل مع بورت
وحاول بحث عن كلمه بنفس طريقه التي اخبرت عنها فهذا يقودك بسرعه الى مبتغاك
============================================
كود:
void main()
{
// INITIALIZING PORTA
CMCON=0x07;//Configure comparators for digital inputs
ADCON1=0x0f;// Configure A/D for digital inputs
//INITIALIZING PORTB
ADCON1=0x0E;//Set RB<4:0> as for digital inputs
//INITIALIZING PORTE
ADCON1=0xA0;//Configure A/D for digital inputs
CMCON=0x07;//Configure comparators for digital inputs
trisa=0;
trisb=0;
trisc=0;
trisd=0;
latb=0;
while(1)
{
portb=0;
porta=0;
portc=0;
portd=0;
delay_ms(100);
porta=0xff;
portb=0xff;
portc=0xff;
portd=0xff;
delay_ms(100);
}
}