各位前辈帮分析一下,这个计数器怎么每次计数到99 , 999......就会调用一下show_log这个函数?谢谢!程序如下;
#device PIC16F87
#fuses HS, NOWDT,PUT, NOBROWNOUT, NOLVP, NOPROTECT, NOCPD,NOWRT
#use delay (clock = 4000000)
typedef unsigned char uchar;
typedef unsigned int8 uint;
typedef int1 bit;
#include "pic16F87.h"
const uchar display[]={" Welcom to use "};
const uchar display1[]={"TEST Tool!"};
const uchar display2[]={"Voltage: V"};
const uchar disp_count[]={"Count:"};
const uchar disp_hex[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
//--------------------------------------------------------------
#define LCD_RS RB5
#define LCD_EN RB6
//-------------初始化端口-----------------------------------------
void init_misc(void)
{ TRISA = 0x00;
TRISB = 0x0;
TRISC = 0x0;
PORTA = 0x00; //
PORTB = 0x00;
PORTC = 0x00; //
ADCON1 = 0x07;//
}
//----------写指令--------------------------------------
void write_com(uchar com)
{
PORTC = com&0xf0; // 传送高4?
LCD_RS = 0; // 指令
LCD_EN = 1;
delay_us(20) ;
LCD_EN = 0; // 产生下降沿,写时序
PORTC = (com&0x0f)<<4; // 传送低4位
LCD_EN = 1;
delay_us(20) ;
LCD_EN = 0; // 产生下降沿,写时序
}
//---------------写数据
void write_dat( uchar lcd_data)
{
PORTC = lcd_data&0xf0; // 传送高4位
LCD_RS = 1; // 数据
LCD_EN = 1;
delay_us(20);
LCD_EN = 0; // 产生下降沿,写时序
PORTC = (lcd_data&0x0f)<<4; // 传送高4位
LCD_EN = 1;
delay_us(20);
LCD_EN = 0; // 产生下降沿,写时序
}
void init_lcd()
{
delay_ms(30);
write_com(0x30);//
delay_ms(20);
write_com(0x30);//
delay_ms(20);
write_com(0x30);//
delay_ms(20);
write_com(0x20);//
delay_ms(2);
write_com(0x28);//DL=0:四位,N=1;双显,F=0?5*7点阵显示
delay_ms(2);
write_com(0X0C);//显示开,光标不显示,不闪烁//0x0c
delay_ms(2);
write_com(0x01);//清屏
delay_ms(2);
write_com(0x06);//光标不动,字符右移
delay_ms(2);
}
void show_log()
{uchar i;
write_com(0x80); //写地址第一行0地址开始
delay_ms(5);
for(i=0;i<15;i++)
{
write_dat(display[i]);
delay_ms(20);
}
delay_ms(500);
write_com(0x0C3); //第二行地址0x80+0X40
for(i=0;i<12;i++)
{
write_dat(display1[i]);
delay_ms(20);
}
delay_ms(1000);
write_com(0x01); //清屏
delay_ms(10);
write_com(0x80); //写地址
for(i=0;i<6;i++)
{
write_dat(disp_count[i]);
delay_ms(50);
}
}
void disp_lcd(uchar a0,a1,a2,a3,a4,a5,a6,a7)
{
write_com(0x87);
write_dat(disp_hex[a0]);
delay_ms(1);
write_com(0x88);
write_dat(disp_hex[a1]);
delay_ms(1);
write_com(0x89);
write_dat(disp_hex[a2]);
delay_ms(1);
write_com(0x8a);
write_dat(disp_hex[a3]);
delay_ms(1);
write_com(0x8b);
write_dat(disp_hex[a4]);
delay_ms(1);
write_com(0x8c);
write_dat(disp_hex[a5]);
delay_ms(1);
write_com(0x8d);
write_dat(disp_hex[a6]);
delay_ms(1);
write_com(0x8e);
write_dat(disp_hex[a7]);
delay_ms(1);
}
//------------------------------------------------------
void main(void)
{
uint R1,a0,a1,a2,a3,a4,a5,a6,a7;
R1=a1=a2=a3=a4=a5=a6=a7=a0=0;
init_misc();
init_lcd();
show_log();
while(1)
{
restart_wdt();
R1++;
delay_ms(1);
while(a0>=10)
{a0-=10;
while(1);
}
while(a1>=10)
{a1-=10;a0++;}
while(a2>=10)
{a2-=10;a1++;}
while(a3>=10)
{a3-=10;a2++;}
while(a4>=10)
{a4-=10;a3++;}
while(a5>=10)
{a5-=10;a4++;}
while(a6>=10)
{a6-=10;a5++;}
while(R1>=10)
{R1-=10;a6++;}
a7=R1;
disp_lcd(a0,a1,a2,a3,a4,a5,a6,a7);
}
} |
|