完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include "US100Test.h"
void Delay1Ms(void); void Delay5Ms(void); void Delay400Ms(void); void UART_ISR(void); void UARTSnd(unsigned char dat); void UART_init(); void init(void); ***it RCK_STMM = P2^7; ***it DIO_DS = P2^6; ***it SCK_SHBit = P2^5; ***it Trig_Mode = P2^0; ***it UART_Mode = P2^1; ***it UART_TEMP = P2^2; ***it Trig_Pin = P1^7; ***it Echo_Pin = P1^6; void InitiOPort() { // P0M1 = 0XFF //p0口设为输入。 P0M1 = 0;//P0口设为双向口,可输入输出 P0M2 = 0;//P0口设为双向口,可输入输出 P2M1 &= 0X0F;//P2口的P2.5,P2.6,P2.7设为双向口,可输入输出 P2M2 &= 0X0F;//P2口的P2.5,P2.6,P2.7设为双向口,可输入输出 } void DisplayLED(unsigned char LEDid, unsigned char Value, unsigned char Isdot) { unsigned char tempa, tempb; unsigned char tempc, tempd; const unsigned char NumValue[11] = {0X40, 0X79, 0X24, 0X30, 0X19, 0X12, 0X02, 0X78, 0X00, 0X10, 0X3F};//0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -. tempa = 1; tempa <<= (LEDid-1); if(Value >= 11)//value should little than 10 Value = 0; tempb = NumValue[Value]; if(Isdot == 0) tempb += 0X80; //begin output tempd = 0X80; for(tempc = 0; tempc < 8; tempc++) { SCK_SHBit = 0; SCK_SHBit = 0; DIO_DS = (tempa&tempd); SCK_SHBit = 1; SCK_SHBit = 1; tempd >>= 1; } tempd = 0X80; for(tempc = 0; tempc < 8; tempc++) { SCK_SHBit = 0; SCK_SHBit = 0; DIO_DS = (tempb&tempd); SCK_SHBit = 1; SCK_SHBit = 1; tempd >>= 1; } RCK_STMM = 0; RCK_STMM = 0; RCK_STMM = 0; RCK_STMM = 0; RCK_STMM = 1; RCK_STMM = 1; RCK_STMM = 1; RCK_STMM = 1; //Delay1Ms(); } void DisplayLength(unsigned long number) { unsigned char Thousand, Hundred, Decade, Unit; if(number > 9999) number = 0; Thousand = number/1000; number = number%1000; Hundred = number/100; number = number%100; Decade = number/10; Unit = number%10; DisplayLED(1, Thousand, 0); DisplayLED(2, Hundred, 0); DisplayLED(3, Decade, 0); DisplayLED(4, Unit, 0); } unsigned long MeterByTrig() { unsigned char tempa; unsigned char IsOverFlow; unsigned long PresentTime, tempb; IsOverFlow = 0; //Delay1Ms(); P1M1 &= 0X7F; P1M2 &= 0X7F; P1M1 |= 0X40; P1M2 &= 0XBF; //Timer Init TMOD = 0X11; TAMOD = 0X00; TCON = 0X00; TH1 = 0; TL1 = 0; Trig_Pin = 0; for(tempa = 0; tempa < 10; tempa++) { Trig_Pin = 1; } Trig_Pin = 0; while(1) { if(Echo_Pin == 1) {//Start Timer; TCON = 0X40;//start timer break; } if(TCON&0X80) { IsOverFlow = 1; break;//overflow; } } while(1) { if(Echo_Pin == 0) {//Stop Timer; TCON = 0X00; break; } if(TCON&0X80) { IsOverFlow = 1; break;//overflow; } } // unsigned long PresentTime, tempb; PresentTime = TH1; PresentTime <<= 0X08; PresentTime += TL1; tempb = PresentTime/137; PresentTime /= 7;//*3 PresentTime -= tempb;//time, us tempb = PresentTime/150; PresentTime /= 3; PresentTime += tempb; //Delay1Ms(); return PresentTime; } void main(void) { unsigned char tempa; unsigned long PreLength; InitIOPort(); while(1) { PreLength = MeterByTrig(); for(tempa = 0; tempa < 200; tempa++) { DisplayLength(PreLength); } } } //1ms延时 void Delay1Ms(void) { unsigned long TempCyc = 90;//36865;//5552; while(TempCyc--); } //5ms延时 void Delay5Ms(void) { unsigned long TempCyc = 460;//36865;//5552; while(TempCyc--); } //400ms延时 void Delay400Ms(void) { unsigned char TempCycA = 80;//5; unsigned long TempCycB; while(TempCycA--) { TempCycB=460;//50000; //7269; while(TempCycB--); }; } |
|
相关推荐
1个回答
|
|
最近我也在想这个问题
|
|
|
|
只有小组成员才能发言,加入小组>>
3053个成员聚集在这个小组
加入小组2974 浏览 1 评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3697 浏览 2 评论
请问怎么把下面51单片机的代码改成msp430 g2 pocket的代码,还有改下时间变成30秒
2366 浏览 1 评论
4832 浏览 1 评论
2593 浏览 1 评论
1449浏览 3评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3700浏览 2评论
2976浏览 1评论
1646浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-25 02:51 , Processed in 1.197519 second(s), Total 80, Slave 65 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号