|
對ARM有興趣可以參考看看
/******************************************************************************************
STM32F103RBT6 电感表 源程序 IAR5.3
作者:杨春亮
2010-05-02 无锡新纺
******************************************************************************************/
#include "main.h"
extern u16 IC2Value ;
extern u32 Frequency ;
extern u32 L_UH ;
unsigned char p4[6]={'0','0','0','0','0','0'} ;
/*定义LCD1602--HC595--STM32的接口
HC595_DS------PB7
HC595_CLK-----PB6
HC595_STCP----PB8
LCD1602_RS----PB9
LCD1602_EN----PD2
LCD1602_R/W---GND
HC595_Q0------LCD1602_D7
HC595_Q1------LCD1602_D6
HC595_Q2------LCD1602_D5
HC595_Q3------LCD1602_D4
HC595_Q4------LCD1602_D3
HC595_Q5------LCD1602_D2
HC595_Q6------LCD1602_D1
HC595_Q7------LCD1602_D0
*/
#define DS_H GPIO_SetBits(GPIOB, GPIO_Pin_7)
#define DS_L GPIO_ResetBits(GPIOB, GPIO_Pin_7)
#define CLK_H GPIO_SetBits(GPIOB, GPIO_Pin_6)
#define CLK_L GPIO_ResetBits(GPIOB, GPIO_Pin_6)
#define STCP_H GPIO_SetBits(GPIOB, GPIO_Pin_8)
#define STCP_L GPIO_ResetBits(GPIOB, GPIO_Pin_8)
#define RS_H GPIO_SetBits(GPIOB, GPIO_Pin_9)
#define RS_L GPIO_ResetBits(GPIOB, GPIO_Pin_9)
#define EN_H GPIO_SetBits(GPIOD, GPIO_Pin_2)
#define EN_L GPIO_ResetBits(GPIOD, GPIO_Pin_2)
void LCD1602_init (void);
void LCD1602_clear (void);
void LCD1602_write_char (unsigned char command,unsigned char data);
void LCD1602_set_xy (unsigned char x, unsigned char y);
void LCD1602_write_string (unsigned char X,unsigned char Y,unsigned char *s);
void WriteSIOByte (unsigned char lcd );
void GPIO_Configuration(void)
{
//定义一个GPIO结构体
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_ResetBits(GPIOB, GPIO_Pin_6);
GPIO_ResetBits(GPIOB, GPIO_Pin_7);
GPIO_ResetBits(GPIOB, GPIO_Pin_8);
GPIO_ResetBits(GPIOB, GPIO_Pin_9);
GPIO_ResetBits(GPIOD, GPIO_Pin_2);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* TIM2 channel 2 pin (PA.01) configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void delay_ms(u16 t)
{
u16 i,j;
for (i=0;i<t;i++)
{
for (j=0;j<6000;j++) {;}
}
}
void itoa( u32 n,unsigned char *str)
{
int i;
unsigned char j,p;
i=1000000;
p=0;
do
{
j=(unsigned char) (n/i);
if (j || p || (i==1))
{
*str++=j+'0';
p=1;
}
n%=i;
i/=10;
}
while (i!=0);
*str=0;
}
int main(void)
{
TIM_ICInitTypeDef TIM_ICInitStructure;
u32 timer;
#ifdef DEBUG
debug();
#endif
//初始参数设置
/********************配置函数功能*******************************/
RCC_Configuration(); //配置系统时钟
NVIC_Configuration(); //配置 NVIC 和 Vector Table
GPIO_Configuration(); //使用的GPIO口
u8 p1[]="---L-METER---";
u8 p2[]="yarp888@126.com";
u8 p3[]=" Lx= ";
u8 p5[]="uH";
u8 p6[]="-OVER-";
for ( timer =50000;timer >0;timer--)
{
}
GPIO_ResetBits(GPIOB, GPIO_Pin_6);
GPIO_ResetBits(GPIOB, GPIO_Pin_7);
GPIO_ResetBits(GPIOB, GPIO_Pin_8);
GPIO_ResetBits(GPIOB, GPIO_Pin_9);
GPIO_ResetBits(GPIOD, GPIO_Pin_2);
WriteSIOByte(0);
LCD1602_init();
LCD1602_clear(); //显示清屏
//-------------------------------------------------------------
/* TIM2 configuration: PWM Input mode ------------------------
The external signal is connected to TIM2 CH2 pin (PA.01),
The Rising edge is used as active edge,
The TIM2 CCR2 is used to compute the frequency value
------------------------------------------------------------ */
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_PWMIConfig(TIM2, &TIM_ICInitStructure);
/* Select the TIM2 Input Trigger: TI2FP2 */
TIM_SelectInputTrigger(TIM2, TIM_TS_TI2FP2);
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);
/* Enable the Master/Slave Mode */
TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);
LCD1602_clear(); //显示清屏
LCD1602_write_string(2,0,p1);
LCD1602_write_string(1,1,p2);
delay_ms(1000);
/* TIM enable counter */
TIM_Cmd(TIM2, ENABLE);
/* Enable the CC2 Interrupt Request */
TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);
while(1)
{
/* Frequency computation */
Frequency=72000000/IC2Value ;
L_UH = 25330338000000/Frequency/Frequency;
if (L_UH <=999999) itoa(L_UH,p4);
TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
LCD1602_clear(); //显示清屏
LCD1602_write_string(2,0,p1);
LCD1602_write_string(0,1,p3);
if (L_UH <=999999)
{
LCD1602_write_string(6,1,p4);
LCD1602_write_string(13,1,p5);
}
else
{
LCD1602_write_string(6,1,p6);
}
delay_ms(1000);
}
}
/**********************************************************
下列連結為原資料來源,如有侵權,或不妥,請連絡管理員或本人,將會盡速處理
http://218.16.124.207/bbs/bbs_co ... ang&bbs_id=9999 |
|