dz̸STM32F10XоƬSysTickϵͳʱÖÓ¶¨Ê±Æ÷
1¡¢½éÉÜ
ʵÏÖCortex-M3ϵͳ¶¨Ê±Æ÷SysTickµÄÅäÖã¬ÐèÒª¾ß±¸ÒÔÏÂ֪ʶ£ºCortex-M3ϵͳ¶¨Ê±Æ÷ĬÈÏƵÂÊÊÇHCLKµÄ8·ÖƵ£¨ÈçÏÂͼËùʾ£©£¬Òò´ËÐèÒª»áRCCʱÖÓµÄÅäÖã»È»ºóÅäÖÃSysTickϵͳ¶¨Ê±Æ÷£»±àдSysTickÖжϴ¦Àíº¯Êý¡£
ϵͳʱÖÓ¼°ÏµÍ³¶¨Ê±Æ÷ʱÖÓ£¨Ïê¼ûÊֲᣩ
2¡¢¼Ä´æÆ÷ÃèÊö
lSysTick¿ØÖƼ°×´Ì¬¼Ä´æÆ÷STK_CTRL
lSysTickÖØ×°ÔØÊýÖµ¼Ä´æÆ÷STK_LOAD
lSysTickµ±Ç°ÊýÖµ¼Ä´æÆ÷STK_VAL
lSysTickУ׼ÊýÖµ¼Ä´æÆ÷STK_CALIB
ÓëSysTickÏà¹ØµÄ¹Ì¼þ¿âº¯ÊýÓÐÒÔϼ¸¸ö£º
lÅäÖÃSysTickϵͳʱÖÓ£ºSysTick_CLKSourceConfig();
lÉèÖÃSysTickÖØ×°Öµ£ºSysTick_SetReload();
lʹÄÜ»ò³ýÄÜSysTick¶¨Ê±Æ÷£ºSysTick_CounterCmd();
lʹÄÜ»ò³ýÄÜSysTick¶¨Ê±Æ÷ÖжϣºSysTick_ITConfig();
l»ñÈ¡SysTickʱÖÓµ±Ç°Öµ£ºSysTick_GetCounter();
l¼ì²âSysTick±ê־λÊÇ·ñÉèÖãºSysTICK_GetFlagStatus();
3¡¢SysTickÅäÖÃÁ÷³Ì
?Ê×ÏÈÅäÖÃRCC£ºÑ¡ÔñϵͳʱÖÓ¡¢ÅäÖÃ×ÜÏßʱÖÓ¡¢Ê¹ÄÜÍâΧÉ豸ʱÖӵȣ»
?ÅäÖÃNVIC£ºÑ¡ÔñÖжÏÓÅÏȼ¶×飬ÉèÖÃSysTickÖжÏÓÅÏȼ¶£¬Ê¹ÄÜSysTickÖжÏͨµÀ£»
?±àдSysTickÖжϴ¦Àíº¯Êý£»
?ÅäÖÃSysTickʱÖÓ£º
nÉèÖÃSysTickʱÖÓÔ´£¨²»ÐèÒª£¬Ä¬ÈÏÑ¡ÔñHCLKµÄ8·ÖƵ×÷ΪSysTickϵͳ¶¨Ê±Æ÷µÄʱÖÓÔ´£©£ºµ÷ÓÃSysTick_CLKSourceConfig()º¯Êý£»
nÉèÖÃSysTickʱÖÓÖØ×°Öµ£ºµ÷ÓÃSysTick_SetReload()£»
nʹÄÜSysTickʱÖÓÖжϣ¨¸ù¾Ý¾ßÌåÓ¦ÓÃÐèÒª£©£ºµ÷ÓÃSysTick_ITConfig()º¯Êý£»
?ʹÄÜSysTickʱÖÓ£ºµ÷ÓÃSysTick_CounterCmd()º¯Êý£»
È»ºó»¹¿ÉÒÔµ÷ÓÃSysTick_GetCounter()º¯Êý»ñÈ¡SysTickϵͳʱÖÓ¼ÆÊýÆ÷µÄµ±Ç°Öµ£»Ò²¿ÉÒÔµ÷ÓÃSysTick_GetFlagStatus()º¯Êý¼ì²éÖ¸¶¨µÄSysTick±ê־λÊÇ·ñÉèÖã¨Ã»ÓпªÆôÖжϣ¬Í¨¹ýÈí¼þ²éѯ·½Ê½¼ì²éϵͳ¶¨Ê±Æ÷ÊÇ·ñ¼ÆÊýµ½0£©¡£
SysTickϵͳ¶¨Ê±Æ÷µÄÖжϱê־λÔÚϵͳʱÖÓ½ÚÅÄ¿ØÖÆÓë״̬¼Ä´æÆ÷CTRLµÄCOUNTFLAG룬¸ÃλÓɶ¨Ê±Æ÷¼ÆÊýµ½0ÖÃ1£¬¶ÁȡʱÇåÁã¡£Òò´Ë¿ÉÒÔµ÷Óú¯ÊýSysTick_GetFlagStatus(SysTick_FLAG_COUNT)À´Çå³ýCOUNTFLAG±ê־λ¡£
¾¹ý²âÊÔ£º²»µ÷ÓÃSysTick_GetFlagStatus(SysTick_FLAG_COUNT)º¯ÊýÀ´Çå³ý±ê־룬ÔÚÿ´ÎϵͳʱÖÓ½ÚÅÄSysTickÔÚ¼ÆÊýΪ0ʱ£¬Ò²¶¼ÄܽøÈëÖжϴ¦Àíº¯Êý¡£µ«³ÌÐòµÄÑÏÃÜÐÔ¿¼ÂÇ£¬×îºÃ»¹Êǵ÷Óøú¯Êý¡£
4¡¢SysTickϵͳ¶¨Ê±Æ÷Àý×Ó
Àý×Ó1£º
/*Ö÷º¯ÊýÖÐÅäÖã¬ÕâÀïûÓÐÑ¡ÔñSysTickµÄʱÖÓÔ´£¬ÊÇÒòΪc8оƬÒѾ½«¸ÃʱÖӹ̻¯³ÉHCLKµÄ8·ÖƵÁË*/
SysTick_SetReload(9000);
SysTick_ITConfig(ENABLE);
SysTick_CounterCmd(SysTick_Counter_Enable);
/*Öжϴ¦Àíº¯Êý*/
void SysTick_Handler(void)/* 1msÖжÏÒ»´Î*/
{
if(SET == SysTick_GetFlagStatus(SysTick_FLAG_COUNT))/*¶Á±ê־λ£¬Í¬Ê±Çå³ý±ê־λ*/
{
SysCount++;
if(500 == SysCount)
{
SysCount = 0;
count++;
}
}
}
Àý×Ó2£º
/*Ö÷º¯ÊýÅäÖÃ*/
SysTick_SetReload(9000);
SysTick_ITConfig(ENABLE);
/*ÑÓʱº¯Êý£¬ÑÓʱnms */
void Delay(u32 nTime)
{
//¿ªÆôSysTick¼ÆÊýÆ÷
SysTick_CounterCmd(SysTick_Counter_Enable);
TimingDelay = nTime;
while(TimingDelay != 0);//ËÀµÈ´ý
//¹Ø±ÕϵͳµÎ´ð
SysTick_CounterCmd(SysTick_Counter_Disable);
//Çå³ýSysTick¼ÆÊýÆ÷
SysTick_CounterCmd(SysTick_Counter_Clear);
}
/*Öжϴ¦Àíº¯Êý*/
void SysTick_Handler(void)
{/*ûÓÐÇå³ý±ê־룬ÔÚ¼ÆÊýΪ0ʱ£¬Í¬Ñù¿ÉÒÔ½øÈëÖжϴ¦Àíº¯ÊýʵÏÖTimingDelay×Ô¼õ¹¤×÷*/
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
STM32F10XоƬSysTickϵͳʱÖÓ¶¨Ê± Ïà¹ØÎÄÕ£º
- Windows CE ½ø³Ì¡¢Ï̺߳ÍÄÚ´æ¹ÜÀí(11-09)
- RedHatLinuxÐÂÊÖÈëÃŽ̳Ì(5)(11-12)
- uClinux½éÉÜ(11-09)
- openwebmailV1.60°²×°½Ìѧ(11-12)
- LinuxǶÈëʽϵͳ¿ª·¢Æ½Ì¨Ñ¡ÐÍ̽ÌÖ(11-09)
- Windows CE ½ø³Ì¡¢Ï̺߳ÍÄÚ´æ¹ÜÀí(¶þ)(11-09)