|
/* MAIN.C file
*
* Copyright (c) 2002-2005 STMicroelectronics
*/
#include "stm8s207R8.h"
#include "prohead.h"
unsigned long frequency;
unsigned int captureValue1,captureValue2;
unsigned char gewei,shiwei,baiwei,qianwei;
unsigned char dis[]={0xc0,0xf9,0xa4,0xb0,0x99,0x82,0xf8,0x80,0x90};
void TIM1_Init(void);
void CCO_Init(void);
void GPIO_Init(void);
void Display(void);
void Delay(unsigned int t);
void main()
{
unsigned int i;
CLK_CKDIVR = 0x00;
GPIO_Init();
CCO_Init();
TIM1_Init();
while(1)
{
TIM1_CCER1 |= 0x01;
while((TIM1_SR1 & 0x02) == 0);
captureValue1 = (unsigned int)TIM1_CCR1H << 8;
captureValue1 |= TIM1_CCR1L;
while((TIM1_SR1 &0x02) ==0);
captureValue2 = (unsigned int)TIM1_CCR1H << 8;
captureValue2 |= TIM1_CCR1L;
TIM1_CCER1 &= 0xfe;
frequency = (8 * 16000000UL)/(captureValue2 - captureValue1);
frequency = frequency/100;
for(i = 0;i<500;i++) Display();
}
}
void CCO_Init(void)
{
CLK_CCOR |= 0x02;
CLK_CCOR |= 0x01;
}
void TIM1_Init(void)
{
TIM1_CCMR1 |= 0x01;
TIM1_CCMR1 |= (0x03<<2);
TIM1_CR1 |= 0x01;
}
void GPIO_Init(void)
{
PG_ODR = 0xff;
PG_DDR = 0xff;
PG_CR1 = 0xff;
PG_CR2 = 0xff;
PB_ODR = 0xff;
PB_DDR = 0xff;
PB_CR1 = 0xff;
PB_CR2 = 0xff;
}
void Display(void)
{
qianwei = frequency/1000;
baiwei = (frequency%1000)/100;
shiwei = (frequency%100)/10;
gewei = frequency%10;
PG_ODR = dis[gewei];
PB_ODR = 0x080;
Delay(100);
PB_ODR = 0x00;
PG_ODR = dis[shiwei]&0x7f;
PB_ODR = 0x40;
Delay(100);
PG_ODR = dis[baiwei];
PB_ODR = 0x20;
Delay(100);
PG_ODR = dis[qianwei];
PB_ODR = 0x10;
Delay(100);
PB_ODR = 0x00;
}
void Delay(unsigned int t)
{
while(t--);
}
程序比較簡單 就不一一注釋啦
|
|