/************************************************************************
Name: 流水灯
Copyright: 唐湘衡
Author: 唐湘衡
Date: 24-10-09 11:25
Description:
功能:用c端口实现点亮两边两个灯人R0,R7然后向中间闪烁循环
器件:pic18f4520芯片一片,pic-DEMO工程板一块,picMCD2仿真器,台式电脑
要求:选用xt晶振,关闭看门狗定时器和低电压编程
**************************************************************************/
#include
void delay(); //延时函数声明
void main()
{
int left;int right; //left=R7,right=R0
TRISC = 0X00; //c端口为输出,要写于前面
left = 128; right = 1;
PORTC = (left+right); //同时点亮R0和R7
while (1)
{
left=left>>1; right = right<<1;
delay();
if (left>128 || right<1)
{
delay();
left = 128; right = 1;
}
PORTC = (left+right); //再次点亮R0和R7
}
}
//************************************************************************
void delay()
{
int i;
for (i=6000; i>0;i--)
{;}
}