ÂåÑôÀí¹¤Ñ§Ôº±ÏÒµÉè¼Æ£¨ÂÛÎÄ£©
TIM_SelectSlaveMode(SONIC_TIMx, TIM_SlaveMode_Reset); /* Enable the Master/Slave Mode */
TIM_SelectMasterSlaveMode(SONIC_TIMx,
TIM_MasterSlaveMode_Enable);
}
//¶¨Ê±Æ÷ÖжÏÀï±ßµÄÄÚÈÝ void TIMx_IRQHandler(void) { }
30
/* TIM enable counter */
TIM_Cmd(SONIC_TIMx, ENABLE); /* Enable the CC2 Interrupt Request */
TIM_ITConfig(SONIC_TIMx, TIM_IT_CC2, ENABLE);
if(TIM_GetITStatus(SONIC_TIMx,TIM_IT_CC2)!=RESET) {
TIM_ClearITPendingBit(SONIC_TIMx,TIM_IT_CC2); value1=TIM_GetCapture2(SONIC_TIMx); if(value1!=0) {
value2=TIM_GetCapture1(SONIC_TIMx); } else {
value1=0; }
time=value2;
value2=0;
}
ÂåÑôÀí¹¤Ñ§Ôº±ÏÒµÉè¼Æ£¨ÂÛÎÄ£©
//12864Òº¾§ÏÔʾģ¿é³õʼ»¯
//³õʼ»¯Òº¾§£¬Òý½Å³õʼ»¯£¬·¢Ëͳõʼ»¯ÃüÁî void initlcd12864() { }
//Òº¾§Òý½Å×ÊÔ´³õʼ»¯ void GPIO_Config(void) {
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOx|RCC_APB2PGPIO_Config(); write_com(0x30); delayms(1);
write_com(0x0c);//ÕûÌåÏÔʾ¿ª ÓÎ±ê¹Ø ÓαêλÖÃ¹Ø delayms(1); write_com(0x01); delayms(5);
eriph_GPIOy,ENABLE);
GPIO_InitStructure.GPIO_Pin
=
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOx, &GPIO_InitStructure);
GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOy, &GPIO_InitStructure);
31
ÂåÑôÀí¹¤Ñ§Ôº±ÏÒµÉè¼Æ£¨ÂÛÎÄ£©
}
//´òÓ¡ÏÔʾºº×Ö³ÌÐò£¬°üÀ¨É趨ÏÔÊ¾×ø±ê£¬ÏÔʾÄÚÈÝ
void hanzi(unsigned char x,unsigned char y,unsigned char *z) //ÏÔʾºº×Ö ×Ö·û
{ unsigned char pos; if(x==0)
x=0x80;
if(x==1)
x=0x90;
if(x==2)
x=0x88;
if(x==3)
x=0x98;
pos=x+y; write_com(pos); while(*z!='\\0') { write_date(*z);
z++;
}
}
32
ÂåÑôÀí¹¤Ñ§Ôº±ÏÒµÉè¼Æ£¨ÂÛÎÄ£©
//Ö÷º¯ÊýÄÚÈÝ int main(void) {
while(1) {
a=Sonic1(); b=Sonic2(); c=Sonic3(); d=Sonic4(); if(a<=100)
else
hanzi(0,0,\ºÅ³µÎ»Óгµ\
u8 a,b,c,d; SystemInit();
GPIO_Configuration();//´®¿ÚÒý½Å³õʼ»¯
USART_Configuration(9600);//´®¿Ú³õʼ»¯£¬·½±ãϵͳµ÷ÊÔ Delay_Configuration(72);//ϵͳÑÓʱº¯Êý³õʼ»¯ Sonic_Init();//³¬Éù²¨³õʼ»¯
initlcd12864();//Òº¾§ÏÔʾģ¿é³õʼ»¯
printf(\//³õʼ»¯½áÊø ´®¿Ú´òÓ¡OKÐÅÏ¢
hanzi(0,0,\ºÅ³µÎ»ÎÞ³µ\
if(b<=100) hanzi(0,0,\ºÅ³µÎ»Óгµ\
else
hanzi(0,0,\ºÅ³µÎ»ÎÞ³µ\
if(c<=100) hanzi(0,0,\ºÅ³µÎ»Óгµ\
else
hanzi(0,0,\ºÅ³µÎ»ÎÞ³µ\
}
if(d<=100) hanzi(0,0,\ºÅ³µÎ»Óгµ\
else
hanzi(0,0,\ºÅ³µÎ»ÎÞ³µ\
delayms(100);
}
33