单片机计时秒表程序方案设计书.pdf
《单片机计时秒表程序方案设计书.pdf》由会员分享,可在线阅读,更多相关《单片机计时秒表程序方案设计书.pdf(14页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、pic 单片机计时秒表程序设计(时钟显示范围00.0099.99 秒,分辨度为0.01 秒)作者:来源:本站原创点击数:1676 更新时间:2008 年 07 月 12 日/此程序实现计时秒表功能,时钟显示范围00.0099.99 秒,分辨度:0.01 秒#include p18f458.hunsigned char s4。/定义 0.01 秒、0.1 秒、1 秒、10秒计时器unsigned char k,data,sreg。unsigned int i。const table11=0 xc0,0 xf9,0 xa4,0 xb0,0 x99,0 x92,0 x82,0XD8,0 x80,0
2、x90。/不带小数点的显示段码表const table010=0X40,0X79,0X24,0X30,0X19,0X12,0X02,0X78,0X00,0X10。/带小数点的显示段码表void clkint(void)。/TMR0 初始化子程序void tmint()T0CON=0XCF。/设定 TMR0L 工作于 8 位定时器方式/内部时钟,TMR0 不用分频INTCON=0X20。/总中断禁止,TMR0 中断允许,清除TMR0 的中断标志INTCON2bits.TMR0IP=1。/TMR0 中断高优先级RCONbits.IPEN=1。/使能中断优先级/系统其它部分初始化子程序void in
3、itial()TRISA=0 x00。/A 口设置为输出TRISB=0XF0。/RB1 输出,RB4 输入TRISC=0 x00。/SDO 引脚为输出,SCK 引脚为输出TRISE=0 x00。/E 口设置为输出SSPCON1=0 x30。/SSPEN=1。CKP=1,FOSC/4 SSPSTAT=0 xC0。/时钟下降沿发送数据PIR1=0。/清除 SSPIF标志data=0X00。/待显示的寄存器赋初值PORTBbits.RB1=0。PORTAbits.RA3=0。PORTE=0。/将 K1,K2,K3,K4 四条列线置0 /SPI 传输数据子程序void SPILED(char data
4、)SSPBUF=data。/启动发送do 。while(PIR1bits.SSPIF=0)。PIR1bits.SSPIF=0。/显示子程序,显示4 位数void dispaly()PORTAbits.RA5=0。/准备锁存for(k=0。k4。k+)data=sk。if(k=2)data=table0data。/个位需要显示小数点else data=tabledata。SPILED(data)。/发送显示段码 for(k=0。k4。k+)data=0 xFF。SPILED(data)。/连续发送4 个 DARK,使显示好看一些文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9
5、U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:C
6、F2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ
7、5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4
8、K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码
9、:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2
10、HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 Z
11、Z4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5 PORTAbits.RA5=1。/最后给锁存信号,代表显示任务完成/软件延时子程序void DELAY()for(i=3553。-i。)continue。/键扫描子程序void KEYSCAN()while(1)dispaly()。/调用一次显示子程序while(PORTBbits.RB4=0)DELAY()。/若有键按下,则软
12、件延时break。if(PORTBbits.RB4=0)break。/若还有键按下,则终止循环扫描,返回/等键松开子程序void keyrelax()while(1)dispaly()。/调用一次显示子程序if(PORTBbits.RB4=1)break。/为防止按键过于灵敏,每次等键松开才返回 /*高优先级中断向量*/文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2
13、 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1
14、ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文
15、档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9
16、I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B
17、1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N
18、5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5
19、Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5#pragma code InterruptVectorHigh=0 x08 void InterruptVectorHigh(void)_asm goto clkint/跳到中断程序_endasm/中断服务程序#pragma code#pragma interrupt clkint void clkint()TMR0=0X13。/对 TMR0 写入一个调整值。因为写入TMR0 后接着的/两个周期不能增量,中断需要3 个周期的响应时间,/以及 C语言自动进行现场保护要消耗周期INTCONbits.T0IF=0。/清除中断标志sreg=s
20、reg+1。/中断计数器加1 if(sreg=40)/中断次数为40 后,才对S0,S1,S2,S3 操作 sreg=0。s0=s0+1。if(s0=10)s0=0。s1=s1+1。if(s1=10)s1=0。s2=s2+1。if(s2=10)s2=0。s3=s3+1。if(s3=10)s3=0。文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1
21、 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5
22、文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y
23、9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3
24、B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10
25、N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N5Y9I2 HQ5C5X8T3B1 ZZ4K9U2A10N5文档编码:CF2X2N
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 单片机 计时 秒表 程序 方案设计
限制150内