完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
下面这段程序的功能是每组数据从左向右滚动进入显示屏,保持刷新一段时间后显示下一组。我用了两个定时器,T0用作滚动进入计时,T2用作刷新计时。
可是实际T2的刷新计时比设定的长好多,不知道哪里出问题了,还有每组最后一位滚出显示屏会出现乱码的现象,这是为什么呢? 我也希望大家能不吝赐教,写出更好的代码实现该功能。 附件有源程序和仿真图。 #define F_CPU 4000000UL #include #include #include typedef unsigned char uint8; typedef unsigned int uint16; const PROGMEM uint8 SEG_CODE[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, 0xbf, 0xff}; const PROGMEM uint8 SCAN_BITs[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; const PROGMEM uint8 Table_OF_Digits[][16] = { {11, 11, 11, 11, 11, 11, 11, 11, 5, 2, 10, 2, 1, 10, 9, 0}, {11, 11, 11, 11, 11, 11, 11, 11, 9, 3, 10, 7, 5, 10, 1, 2}, {11, 11, 11, 11, 11, 11, 11, 11, 7, 7 ,10, 7, 7, 10, 7, 7} }; uint8 row, col; int main(void) { // uint8 i, j; DDRC = 0xff; PORTC = 0x00; DDRD = 0xff; PORTD = 0x00; TCCR0 = 0x03; //预设分频:64 TCCR2 = 0x00; //预设分频:64 TCNT0 = 256 - F_CPU / 64.0 * 0.004; TCNT2 = 256 - F_CPU / 64.0 * 0.004; tiMSK = _BV(TOIE2) | _BV(TOIE0); sei(); while(1); } ISR(TIMER0_OVF_vect) { static uint8 j = 0; static uint8 Keep_T1 = 0; TCNT0 = 256 - F_CPU / 64.0 * 0.004; // PORTD = 0x00; PORTC = 0xff; PORTC = pgm_read_byte(&SEG_CODE[pgm_read_byte(&Table_OF_Digits[row][(col + j) % 16])]); PORTD = pgm_read_byte(&SCAN_BITs[j]); j = (j + 1) % 8; if (col == 8) { TCCR0 = 0x00; TCCR2 = 0x04; } if (col == 15) row = (row + 1) % 3; if (++Keep_T1 == 15) col = (col + 1) % 16; } ISR(TIMER2_OVF_vect) { static uint8 n = 0; static uint16 Keep_T2 = 0; TCNT2 = 256 - F_CPU / 64.0 * 0.004; // PORTD = 0x00; PORTC = 0xff; PORTC = pgm_read_byte(&SEG_CODE[pgm_read_byte(&Table_OF_Digits[row][col + n])]); PORTD = pgm_read_byte(&SCAN_BITs[n]); n = (n + 1) % 8; if (++Keep_T2 != 10) return; Keep_T2 = 0; TCCR0 = 0x03; TCCR2 = 0x00; }
|
|
相关推荐
1 个讨论
|
|
只有小组成员才能发言,加入小组>>
AVR Atmega16 Bootloader程序与上位机LabView程序
5182 浏览 6 评论
#include <ioavr.h>这个头文件我应该下什么编译器
7796 浏览 0 评论
3075 浏览 2 评论
3128 浏览 1 评论
10110 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 12:28 , Processed in 0.692614 second(s), Total 55, Slave 41 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号