📄 1213.c
字号:
/******************************************************************
* 芯片: PIC16F873A *
* 晶振: 4MHz *
* *
* 使用PICC8.05编译器,MPLAB v7.50调试。 *
* *
******************************************************************/
#include <pic.h>
#define uchar unsigned char
#define uint unsigned int
volatile unsigned char i;
uint y;
uchar x=0;
/**********************************************************
初始化函数:初始化个端口
**********************************************************/
void ioint()
{
OPTION = 0xc8;//全局控制寄存器
INTCON = 0xc0;//中断控制
TRISC = 0x09;//定义RC端口各脚输入输出
TRISB = 0xF0;
PORTC = 0;//端口赋值
//GIE=1;//全局中断使能位
//RBIE=1;//RB电平变化中断使能位
//PEIE=1;//外围模块中断使能位
}
/**********************************************************
k*1ms延时函数
**********************************************************/
void delay(uint k)
{
uint t;
for(;k!=0;k--)
for(t=110;t!=0;t--);
}
/********************************************************
主函数
*********************************************************/
main()
{
ioint();
while(1)
{
x=0;
RC4=0;
RC5=0;
RC6=0;
RC7=0;
delay(300);
RC1=1;
RC2=0;
delay(3);
//int i;//在这定义i不可以
#asm
movlw 0x0f
movwf _i ;将0x0f赋值给C中定义的变量i
delay1 bcf _PORTC,1 ;RC1=0
bsf _PORTC,2 ;RC2=1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
bsf _PORTC,1 ;RC1=1
bcf _PORTC,2 ;RC2=0
nop
nop
nop
nop
nop
nop
nop
nop
decfsz _i ;i-1=0则跳过下一条指令
goto delay1
bcf _PORTC,1 ;RC1=0
bcf _PORTC,2 ;RC2=0
nop
#endasm
while(RC3==1){;}
while(RC3==0&&x<58)
{
#asm
movlw 0x17
movwf _i ;将95赋值给C中定义的变量i
delay2 decfsz _i ;i-1=0则跳过下一条指令
goto delay2
#endasm
x=x+1;
}
while(RC3==1&&x<58)
{
#asm
movlw 0x25
movwf _i ;将45赋值给C中定义的变量i
delay3 decfsz _i ;i-1=0则跳过下一条指令
goto delay3
#endasm
x=x+1;
}
y=x*34/2;
if(y<=350)
{
RC4=1;
delay(50);
}
if(y>350&&y<=500)
{
RC5=1;
delay(50);
}
if(y>500&&y<=650)
{
RC6=1;
delay(50);
}
else if (y>650)
{
RC7=1;
delay(50);
}
}
}
/****************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -