笔误了吧,应该是PIC16F883,就是“RE3/MCLR/VPP”脚复位,低电平复位。因为和VPP脚复用,在线编程的时候必需断开才行,正常工作时加一个电阻、电容复位。
//程序如下#include <pic.h>
#define _XTAL_FREQ 4000000
__CONFIG(INTIO & WDTDIS & PWRTDIS& MCLRDIS & UNPROTECT & BORDIS & IESODIS & FCMDIS)
void main(void){
ANSEL =0x00
ANSELH=0x00
ADCON0=0x00
inta=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0
if(RB5==0){
TRISA =0x00
TRISB =0x30
TRISC =0x00
while(1){
if(RB4==1){
PORTC=0xb6PORTA=0x01
__delay_ms(100) __delay_ms(100)
if(RB4==0){
a+=1j+=1
__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100) //在改个函数,程序更紧凑
if(a==3){
PORTA=0x20PORTC=0xb7
break //不要使用, 不然会跳循环。程序结束。
}
if(j==3){
PORTC=0xfePORTA=0x00
break
}
}
PORTC=0x0cPORTA=0x01
__delay_ms(100)__delay_ms(100)
if(RB4==0){
b+=1j+=1
__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)
if(b==3){
PORTA=0x20PORTC=0x0d
break
}
if(j==3){
PORTC=0xfePORTA=0x00
break
}
}
PORTC=0x24PORTA=0x01
__delay_ms(100)__delay_ms(100)
if(RB4==0){
c+=1j+=1
__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)
if(c==3){
PORTA=0x20PORTC=0x25
break
}
if(j==3){
PORTC=0xfePORTA=0x00
break
}
}
PORTC=0xb0PORTA=0x01
__delay_ms(100)__delay_ms(100)
if(RB4==0){
d+=1j+=1
__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)
if(d==3){
PORTA=0x20PORTC=0xb1
break
}
if(j==3){
PORTC=0xfePORTA=0x00
break
}
}
PORTC=0x60PORTA=0x01
__delay_ms(100)__delay_ms(100)
if(RB4==0){
e+=1j+=1
__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)
if(e==3){
PORTA=0x20PORTC=0x61
break
}
if(j==3){
PORTC=0xfePORTA=0x00
break
}
}
PORTC=0x40PORTA=0x01
__delay_ms(100)__delay_ms(100)
if(RB4==0){
f+=1j+=1
__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)
if(f==3){
PORTA=0x20PORTC=0x41
break
}
if(j==3){
PORTC=0xfePORTA=0x00
break
}
}
PORTC=0x36PORTA=0x01
__delay_ms(100)__delay_ms(100)
if(RB4==0){
g+=1j+=1
__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)
if(g==3){
PORTA=0x20PORTC=0x37
break
}
if(j==3){
PORTC=0xfePORTA=0x00
break
}
}
PORTC=0x00PORTA=0x01
__delay_ms(100)__delay_ms(100)
if(RB4==0){
h+=1j+=1
__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)
if(h==3){
PORTA=0x20PORTC=0x01
break
}
if(j==3){
PORTC=0xfePORTA=0x00
break
}
}
PORTC=0x20PORTA=0x01
__delay_ms(100)__delay_ms(100)
if(RB4==0){
i+=1j+=1
__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)__delay_ms(100)
if(i==3){
PORTA=0x20PORTC=0x21
break
}
if(j==3){
PORTC=0xfePORTA=0x00
break
}
}
}
}
}
}
// 按键使用break,,你就一层while会直接结束。显示小数点是跟你的赋值有关要连硬件调试下参数。
修改后的
#include <pic.h>
#define _XTAL_FREQ 4000000
__CONFIG(INTIO & WDTDIS & PWRTDIS& MCLRDIS & UNPROTECT & BORDIS & IESODIS & FCMDIS)
void delu(int i)
{
while(i--)
__delay_ms(100)
}
void main(void){
unsigned char flg=1 //去掉break,而增加的 是否进入循环的标志。
ANSEL =0x00
ANSELH=0x00
ADCON0=0x00
inta=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0
if(RB5==0){
TRISA =0x00
TRISB =0x30
TRISC =0x00
while(1){
//打开flg 的条件也要增加上
if(RB4==0)flg=1
if(RB4==1&&flg==1){ PORTC=0xb6PORTA=0x01delu(2) //
if(RB4==0){ a+=1j+=1 delu(5)
if(a==3) { PORTA=0x20PORTC=0xb7 flg=0 }
if(j==3) { PORTC=0xfePORTA=0x00 flg=0 }
}
PORTC=0x0cPORTA=0x01delu(2) //
if(RB4==0){ b+=1j+=1 delu(5)
if(b==3) { PORTA=0x20PORTC=0x0d flg=0 }
if(j==3) { PORTC=0xfePORTA=0x00 flg=0 }
}
PORTC=0x24PORTA=0x01delu(2) //
if(RB4==0){ c+=1j+=1 delu(5)
if(c==3) { PORTA=0x20PORTC=0x25 flg=0}
if(j==3) { PORTC=0xfePORTA=0x00 flg=0}
}
PORTC=0xb0PORTA=0x01delu(2) //
if(RB4==0){ d+=1j+=1delu(5)
if(d==3) { PORTA=0x20PORTC=0xb1 flg=0}
if(j==3) { PORTC=0xfePORTA=0x00 flg=0}
}
PORTC=0x60PORTA=0x01delu(2) //
if(RB4==0){ e+=1j+=1 delu(5)
if(e==3) { PORTA=0x20PORTC=0x61 flg=0 }
if(j==3) { PORTC=0xfePORTA=0x00 flg=0}
}
PORTC=0x40PORTA=0x01delu(2) //
if(RB4==0){ f+=1j+=1 delu(5)
if(f==3) { PORTA=0x20PORTC=0x41 flg=0 }
if(j==3) { PORTC=0xfePORTA=0x00 flg=0 }
}
PORTC=0x36PORTA=0x01delu(2) //
if(RB4==0){ g+=1j+=1delu(5)
if(g==3){ PORTA=0x20PORTC=0x37 flg=0}
if(j==3){ PORTC=0xfePORTA=0x00 flg=0}
}
PORTC=0x00PORTA=0x01delu(2) //
if(RB4==0){ h+=1j+=1delu(5)
if(h==3) { PORTA=0x20PORTC=0x01 flg=0}
if(j==3) { PORTC=0xfePORTA=0x00 flg=0}
}
PORTC=0x20PORTA=0x01delu(2) //
if(RB4==0) { i+=1j+=1delu(5)
if(i==3) { PORTA=0x20PORTC=0x21 flg=0}
if(j==3) { PORTC=0xfePORTA=0x00 flg=0}
}
}
}
}
}
//meiyou
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)