** çҹ繤Դ繢ͧ¹ͧ 觼ҹ繵ͧ繴令Ѻ
ҡ բʹ ;ͤ ԡ سѧ¹¤Ѻ ӡ䢢
١ͧ Ѻ
Ѻ˹ѡ
 

PIC mikro C ¹ͧ

㹺͹Ƕ֧ѡá¹ѹѺ

C 鹰ҹ

C ҷ㹡¹ä͹ Фзӧҹ ö¹ẺѺѺ͹ ѡ¹ C ͧǤеǹ鹨ѡ¡ѹ C зӧҹ¨տѧ㹡÷ӧҹ main () ͧ ѧ鹡¹ء駨еͧտѧ main() ء 㹡¹ѧҨ繿ѧ蹷¹ͧ ( Т͡Ƕ֧㹺令Ѻ) пѧҵðҹеͧʴش÷ӧҹШششͧ÷ӧҹͧѧ蹹鹴 ͧ
{ ʴش
} ʴشش
ҧ
main ()
{
- - ǹͧ
}
while(1)
{
- - ǹͧ
}

ѡ¹ä͹

ͧҡ IC PIC PORT ͡ҹ PORT PORT բҹ ö Input Output ѧ鹡͹зӡ¹觧ҹ еͧ˹ PORT ͹Ҩ input Output

TRIS 繤觡˹ʶҹ PORT ҧҨ Input Output ¶ҡͧ Output еͧ˹ 0 ҵͧ Input еͧ˹ 1
TRISA =0x00; // PORT A Output (000 000 ŧ繰ҹ 16 00)
TRISA=0xFF; // PORT A Input (1111 1111 ŧ繰ҹ 16 FF)
TRISB =0x00; // PORT B Output (000 000 ŧ繰ҹ 16 00)
TRISB=0xFF; // PORT B Output (000 000 ŧ繰ҹ 16 FF)
** ŧҹ 16 ҹҡ㹵͹ҹ
͡˹ ʶҹ PORT Ҩҡ˹Ҩ 觢 Ѻҧ
PORT 繤觷ҷͧâͧ PORT 觢͡ 0 1
PORTB=0X01; // PORT B B0 觢 1 (0000 0001 ŧ繰ҹ 16 01)
PORTB=0X02; // PORT B B1 觢 1 (0000 0010 ŧ繰ҹ 16 02)
PORTB=0X04; // PORT B B2 觢 1 (0000 0100 ŧ繰ҹ 16 04)
PORTB=0X08; // PORT B B3 觢 1 (0000 1000 ŧ繰ҹ 16 08)
** ŧҹ 16 ҹҡ㹵͹ҹ
while (1) 繤觷͹㹡÷ӧҹ鹷ӧҹẺͧǹٻ
while(1)
{
PORTB=0X01; < - - ˹觢͡ҡ PORT B0 (俵Դʹ)
}

Delay_ms(); 㹡á˹㹡÷ӧҹͧ觡͹˹ҹµŢ᷹ ms
Delay_ms(500); // ˹ǧ 500 ms
Delay_ms(1000); // ˹ǧ 1000 ms 1 Թҷ

÷ͧ信оԺ

㹡÷ͧ 觷ҹҷ信оԺ 1 ǧ


ٻǧ㹡÷ͧ



Code㹡÷ͧ


͸Ժ
void main()
{
TRISB = 0X00; <- - ˹ PORT B Output
while(1)
{
PORTB=0X01; < - - ˹觢 1 (LED Դ ) ͡ҡ PORT B B0
delay_ms(1000); < - - ˹ǧ㹡ʴ 1 Թҷ
PORTB=0X00; < - - ˹觢 0 (LED Ѻ) ͡ҡ PORT B B0
delay_ms(1000); < - -˹ǧ㹡ʴ 1 Թҷ
}
}

ҡͧ㹡˹ǧǢ ŧö¹Ţ delay_ms Ѻ


¹ 4 .. 2554