• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users






Re: do while 輸出問題
#9
新會員
新會員


查看用戶資訊
引言: 瘋曰:「屁股那去了?」
抱歉聽不懂

我發現第三回圈input輸入要快,才能夠跑第三回圈的程式,感謝各位的指教

發表於: 2009/10/22 12:06
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: do while 輸出問題
#8
資深會員
資深會員


查看用戶資訊
瘋曰:「屁股那去了?」

發表於: 2009/10/22 11:17
The Answer to Life, the Universe, and Everything.
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: do while 輸出問題
#7
資深會員
資深會員


查看用戶資訊
參照:

ivkeytt 寫道:
我將各位的方式都試了一試,把while(input_2 != 0x0c);中的分號拿掉會有compiler錯誤情形。


對ㄝ,那個分號不能少

抱歉,一時不察

發表於: 2009/10/21 21:37
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: do while 輸出問題
#6
新會員
新會員


查看用戶資訊
感謝各位的熱心解答

我將各位的方式都試了一試,把while(input_2 != 0x0c);中的分號拿掉會有compiler錯誤情形。

也感謝版主的指導,上列程式的結果也跑出來了,是我想要的結果。於是我做些修改想再做第三個迴圈試試看,我依序給予的輸入是 0x0a,0x03,0x0b,但他做完第二個迴圈(0x03輸出結束)就停止了
請問一下問題出在哪?

#include<pic.h>
main()

{
TRISD=0B00000000;
TRISC=0B11111111;
unsigned char input_1=0,input_2=0,input_3=0;
do
{
input_1= PORTC & 0x0f;
}
while(input_1 != 0x0a);
PORTD=input_1;

do
{
input_2= PORTC & 0x0f;
}
while(input_2 == input_1);
PORTD=input_2;

do
{
input_3= PORTC & 0x0f;
}
while(input_3 == input_2);
PORTD=input_3;
}

發表於: 2009/10/21 20:11
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: do while 輸出問題
#5
版主
版主


查看用戶資訊
" int input_1,input_2; "

插花一下,PORTC & PORTD 都是 unsigned char 的資料型態,所以 input_1 & input_2 最好也是 unsigned char 的型態。

發表於: 2009/10/20 9:13
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: do while 輸出問題
#4
新會員
新會員


查看用戶資訊
do
{
input_2= PORTC & 0x0f;
}
while(input_2 != 0x0c);
PORTD=0X06;

改成

do
{
input_2= PORTC & 0x0f;
}
while(input_2 != 0x06);
PORTD=0X06;

發表於: 2009/10/20 8:57
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: do while 輸出問題
#3
資深會員
資深會員


查看用戶資訊
while(input_2 != 0x0c); <==把 ; 拿掉吧

發表於: 2009/10/18 12:37
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: do while 輸出問題
#2
資深會員
資深會員


查看用戶資訊
參照:

ivkeytt 寫道:
各位好,我使用的是 pic16f877 用hi-tech compiler

我想利用程式做兩個do while迴圈讀portc資料作判斷,再將資料由portd顯示

我在mplab跑時,沒發現問題

但在實際板子上做時,第一迴圈可以按照我的程式跑出0x03,但是第二個回圈卻無法跳出做0x06

我懷疑是portc的問題,但又不知從何改起

懇請大家幫幫忙

以下程式
#include<pic.h>
main()

{
TRISD=0B00000000;
TRISC=0B11111111;
int input_1,input_2;
do
{
input_1= PORTC & 0x0f;
}
while(input_1 != 0x03);

PORTD=input_1;

do
{
input_2= PORTC & 0x0f;
}
while(input_2 != 0x0c;
PORTD=0X06;
}

發表於: 2009/10/18 6:13
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


do while 輸出問題
#1
新會員
新會員


查看用戶資訊
各位好,我使用的是 pic16f877 用hi-tech compiler

我想利用程式做兩個do while迴圈讀portc資料作判斷,再將資料由portd顯示

我在mplab跑時,沒發現問題

但在實際板子上做時,第一迴圈可以按照我的程式跑出0x03,但是第二個回圈卻無法跳出做0x06

我懷疑是portc的問題,但又不知從何改起

懇請大家幫幫忙

以下程式
#include<pic.h>
main()

{
TRISD=0B00000000;
TRISC=0B11111111;
int input_1,input_2;
do
{
input_1= PORTC & 0x0f;
}
while(input_1 != 0x03);

PORTD=input_1;

do
{
input_2= PORTC & 0x0f;
}
while(input_2 != 0x0c);
PORTD=0X06;
}

發表於: 2009/10/11 10:03
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------