欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
51單片機驅動TM1637 固定地址 程序能優化嗎?
[打印本頁]
作者:
mtt661
時間:
2022-8-29 09:34
標題:
51單片機驅動TM1637 固定地址 程序能優化嗎?
我是個單片機愛好者,喜歡驅動各類數碼管,網上TM1637都是地址+1模式,我改了個固定地址模式,請問我這種代碼能優化簡寫嗎?這個代碼仿真通過了。不是很懂C語言。
void SmgDisplay(unsigned char Wei,i) //寫顯示寄存器
{
I2CStart();
I2CWrByte(0x44); // 40H 地址自動加 1 模式,44H 固定地址模式,本程序采用固定地址模式
I2CStop();
I2CStart();
if(Wei==1)
{
I2CWrByte(0xc0); //設置 地址,
I2CWrByte(Num[i]); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc1); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc2); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc3); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc4); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc5); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
}
if(Wei==2)
{
I2CWrByte(0xc0); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc1); //設置 地址,
I2CWrByte(Num[i]); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc2); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc3); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc4); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc5); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
}
if(Wei==3)
{
I2CWrByte(0xc0); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc1); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc2); //設置 地址,
I2CWrByte(Num[i]); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc3); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc4); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc5); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
}
if(Wei==4)
{
I2CWrByte(0xc0); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc1); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc2); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc3); //設置 地址,
I2CWrByte(Num[i]); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc4); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc5); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
}
if(Wei==5)
{
I2CWrByte(0xc0); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc1); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc2); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc3); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc4); //設置 地址,
I2CWrByte(Num[i]); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc5); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
}
if(Wei==6)
{
I2CWrByte(0xc0); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc1); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc2); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc3); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc4); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
I2CWrByte(0xc5); //設置 地址,
I2CWrByte(Num[i]); //送數據
I2CStop();
I2CStart();
}
I2CWrByte(0x8f); //開顯示 ,最大亮度
I2CStop();
復制代碼
作者:
飛云居士
時間:
2022-9-6 17:17
可以用do。。。while循環或for循環語句簡化。
作者:
188610329
時間:
2022-9-8 00:07
要優化的話……
第一步就是 改成 地址+1 模式。
你還想優化么?
作者:
mtt661
時間:
2022-9-23 15:54
閑來無事,優化了一下,現在好點了。
for(j=0;j<6;j++)
{
if(Wei==j)
{
I2CWrByte(0xc0+j); //設置 地址,
I2CWrByte(Num[i]); //送數據
I2CStop();
I2CStart();
}
else
{
I2CWrByte(0xc0+j); //設置 地址,
I2CWrByte(Numoff); //送數據
I2CStop();
I2CStart();
}
}
復制代碼
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1