完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
/////////////////////////////////////
// Generated Initialization File // ///////////////////////////////////// #include "C8051F040.h" ***it LED2=P4^0; unsigned char count,sfrt; // Peripheral specific initialization functions, // Called from the Init_Device() function void Port_IO_Init() { // P0.0 - Unassigned, Open-Drain, Digital // P0.1 - Unassigned, Open-Drain, Digital // P0.2 - Unassigned, Open-Drain, Digital // P0.3 - Unassigned, Open-Drain, Digital // P0.4 - Unassigned, Open-Drain, Digital // P0.5 - Unassigned, Open-Drain, Digital // P0.6 - Unassigned, Open-Drain, Digital // P0.7 - Unassigned, Open-Drain, Digital // P1.0 - Unassigned, Open-Drain, Digital // P1.1 - Unassigned, Open-Drain, Digital // P1.2 - Unassigned, Open-Drain, Digital // P1.3 - Unassigned, Open-Drain, Digital // P1.4 - Unassigned, Open-Drain, Digital // P1.5 - Unassigned, Open-Drain, Digital // P1.6 - Unassigned, Open-Drain, Digital // P1.7 - Unassigned, Open-Drain, Digital // P2.0 - Unassigned, Open-Drain, Digital // P2.1 - Unassigned, Open-Drain, Digital // P2.2 - Unassigned, Open-Drain, Digital // P2.3 - Unassigned, Open-Drain, Digital // P2.4 - Unassigned, Open-Drain, Digital // P2.5 - Unassigned, Open-Drain, Digital // P2.6 - Unassigned, Open-Drain, Digital // P2.7 - Unassigned, Open-Drain, Digital // P3.0 - Unassigned, Open-Drain, Digital // P3.1 - Unassigned, Open-Drain, Digital // P3.2 - Unassigned, Open-Drain, Digital // P3.3 - Unassigned, Open-Drain, Digital // P3.4 - Unassigned, Open-Drain, Digital // P3.5 - Unassigned, Open-Drain, Digital // P3.6 - Unassigned, Open-Drain, Digital // P3.7 - Unassigned, Open-Drain, Digital SFRPAGE = CONFIG_PAGE; P4MDOUT = 0x01; P6MDOUT = 0x18; XBR2 = 0x40; } void Timer_Init() { sfrt = SFRPAGE; SFRPAGE = TIMER01_PAGE; CKCON = 0X01; TMOD = 0x10; //T1·½Ê½1 TH1 = 0x3c; TL1 = 0xb0; //³õÖµ ¶¨Ê±50ms ¼ÆË㹫ʽ 2µÄ16´Î·½-50ºÁÃë/1us = 65536-50000000/1000 = 65536-50000=15536=0x3CB0; ET1 = 1; //ÔÊÐíTIMER1¶¨Ê±Æ÷ÖÐ¶Ï EA = 1; //×ÜÖж˿ª¿ªÆô TR1 = 1; //Æô¶¯¶¨Ê±Æ÷ SFRPAGE = sfrt; } void Oscillator_Init() { int i = 0; SFRPAGE = CONFIG_PAGE; OSCXCN = 0x67; for (i = 0; i < 3000; i++); // Wait 1ms for initialization while ((OSCXCN & 0x80) == 0); CLKSEL = 0x01; OSCICN = 0x00; } void delay() { unsigned int tn = 8000; while ( --tn != 0 ); } // Initialization function for device, // Call Init_Device() from your main program void Init_Device(void) { Port_IO_Init(); } void main() { Init_Device(); delay(); Timer_Init(); Oscillator_Init(); while(1); /* { P4 = 0x00; P6 = 0x00; delay();delay();delay();delay();delay(); LED2 = 1; P6 = 0xff; P4 = 0xff; delay();delay();delay();delay();delay(); };*/ } void Timer1_ISR() interrupt 3 { SFRPAGE = TIMER01_PAGE; ET1 = 0; //ÔÊÐíTIMER1¶¨Ê±Æ÷ÖÐ¶Ï TF1 = 0; TH1 = 0x3c; TL1 = 0xb0; //³õÖµ ¶¨Ê±50ms ¼ÆË㹫ʽ 2µÄ16´Î·½-50ºÁÃë/1us = 65536-50000000/1000 = 65536-50000=15536=0x3CB0; count++; if(count >= 20) { count = 0; P6 = ~P6; } ET1 = 1; } 上述是我C8051F040单片机定时器50MS程序 现在问题的定时器并没有生产50MS的定时,简单来说就是定时器并没有工作, 求个位大神给予帮助 希望能指出相关问题 并给出作答 |
|
相关推荐
3个回答
|
|
问题可能出在两个地方,1.定时初始化 2,定时中断 你可以把断点放在中断里,看看进没进来
void Timer1_ISR() interrupt 3 { SFRPAGE = TIMER01_PAGE; ET1 = 0; //ÔÊÐíTIMER1¶¨Ê±Æ÷ÖÐ¶Ï TF1 = 0; TH1 = 0x3c; TL1 = 0xb0; //³õÖµ ¶¨Ê±50ms ¼ÆË㹫ʽ 2µÄ16´Î·½-50ºÁÃë/1us = 65536-50000000/1000 = 65536-50000=15536=0x3CB0; count++; if(count >= 20) { count = 0; P6 = ~P6; } ET1 = 1; } |
|
|
|
hobbye501 发表于 2017-3-13 11:29 并没有进入定时器中断 能否找出这段程序的问题? 定时器启动我已经看了很多遍 不知道是哪出的问题 |
|
|
|
没进入中断的话 就是初始化问题了 你看看是哪里配置错了 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-使用AHT20进行环境监测之AHT20传感器介绍
828 浏览 0 评论
824 浏览 0 评论
861 浏览 1 评论
基于瑞萨FPB-RA4E2智能床头灯项目——1编译环境搭建与点亮驱动ws2812全彩LED
836 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-LCD显示图片编程示例之介绍mmap
1292 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11821 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-29 09:24 , Processed in 0.701323 second(s), Total 72, Slave 56 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号