📄 cymometer.c
字号:
#include "cymometer.h"
void init()
{
init_timer();
init_capture();
init_lcd();
pulse_count = 2; //两个脉冲
}
void init_timer()
{
OPTION=0b00000111 ;
TMR0=156; //设置100次机器周期溢出
INTCON =0b10100000 ; // 使能定时器中断
TRISD=0;
}
void interrupt ISR(void)
{
… //保护现场、屏蔽中断(根据实际工程修改)
if(time_out>0)
time_out--;
time_count++;
if((INTCON&0b00000100)!=0)
{
INTCON=INTCON&0b11111011;
TMR0=0;
PORTD++; }
}
… //恢复现场、使能中断(根据实际工程修改)
}
void pulse_1khz()
{
if(time_count_output >= 5)
{
if(state.state_ouput == 0)
{
PORTB |= 0x1;
state.state_ouput = 1;
}
else
{
PORTB &= 0xfe;
state.state_ouput = 1;
}
time_count_output = 0;
}
}
void lcd_busy(void)
{
PORTD=0xff;
nRS_1604;
rw_1604;
CS_1604;
while((PORTD&0x80)==0x80);
nCS_1604;
}
void lcd_cmd(unsigned char cmd)
{
lcd_busy();
nRS_1604;
nRW_1604;
PORTD = cmd;
CS_1604;
delayMs();
nCS_1604;
}
void lcd_data(unsigned char data)
{
lcd_busy();
RS_1604;
nRW_1604;
PORTD = data;
CS_1604;
delayMs();
nCS_1604;
}
void lcd_init()
{
delayMs();
lcd_cmd (0x38);
lcd_cmd(0x08);
lcd_cmd (0x01);
lcd_cmd (0x06);
lcd_cmd (0x0c);
}
void lcd_xy(void)
{
X&=0x0f;
Y&=0x03;
if(Y==0x00)
lcd_cmd(X|0x80);
else if(Y==0x01)
lcd_cmd ((X+0x40)|0x80);
else if(Y==0x02)
lcd_cmd ((X+0x10)|0x80);
else
lcd_cmd ((X+0x50)|0x80);
}
void lcd_show(unsigned char xx,unsigned char yy,unsigned char *string)
{
Y=yy;
for(X=xx;X<16;X++)
{
lcd_xy();
lcd_data(*s);
string++;
delayMs();
}
}
void main()
{
init();
while(1)
{
if(counter_stop == 1)
{
counter_read();
counter_stop=0
}
lcd_refresh();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -