• 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: 雙輸入問題
#6
高級會員
高級會員


查看用戶資訊
已經ok啦 我把它改成下列方式
while(1)
{
Init_Adc();
ADdelay(2);
A2D(0x00);
LCD_Set_Cursor(10,0);
LCD_ItoA(AD_Int.AD_10bit);
ADdelay(10);

I nit_Adc_1();
ADdelay(2);
A2D_1(0x00);
LCD_Set_Cursor(10,1);
LCD_ItoA_1(AD_Int_1.AD_10bit_1);


發表於: 2007/5/16 13:38
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 雙輸入問題
#5
資深會員
資深會員


查看用戶資訊
這個看來是 PICC Workshop 的範例改的,但不曉得為什麼要改成這樣,一進去就 ADGO ? 如果要作完 AD 之後先切 port 準備下次,減少 delay,也是可以,但程式裡並沒有真正去做?

原來的 A2D 是打算以 A2D(0) 作 AN0, A2D(1) 作 AN1, ...
此外,由於 Sample/Hold 要一點時間,我把 delay 放到切換 channel 後、 ADGO 之前,這樣比較直覺:

void A2Dunsigned char channel )
{
    
unsigned char temp;                // Temp storage

    
temp channel << 3;            // Shift channel value three bits left
    
ADCON0 &= 0b11000111;            // Clear channel select bits in ADCON0
    
ADCON0 |= temp;                    // Logically OR shifted channel value into place in ADCON0
 
    
ADdelay(10);

    
ADGO 1;                        // Initiate conversion on selected channel
    
while (ADGO) ;                    // Poll ADGO bit until it clears, indicating conv. done
    
AD_Int.AD_Byte.AD_MSB=ADRESH;
    
AD_Int.AD_Byte.AD_LSB=ADRESL;
}


發表於: 2007/5/16 11:45
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 雙輸入問題
#4
高級會員
高級會員


查看用戶資訊
我剛剛有測試 我的輸入部分是RA1 此行不改變 A2D(0x00); // Get 10-bit A/D result from CH0 單一個輸入A/D沒有問題 所以應該不是這問題 還是我有錯誤

發表於: 2007/5/15 15:21
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 雙輸入問題
#3
高級會員
高級會員


查看用戶資訊
A2D(0x00); // Get 10-bit A/D result from CH0

如果是CH1那是要怎改阿 因為我改過好像一直不對ㄟ 可以指導一下ㄇ

發表於: 2007/5/15 15:12
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 雙輸入問題
#2
版主
版主


查看用戶資訊
參照:
while(1)
{
A2D(0x00); // Get 10-bit A/D result from CH0
LCD_Set_Cursor(10,0);
LCD_ItoA(AD_Int.AD_10bit);
ADdelay(10);

A2D_1(0x00); // Get 10-bit A/D result from CH0
LCD_Set_Cursor(10,1);
LCD_ItoA_1(AD_Int_1.AD_10bit_1);

}


程式裡只看到 CH0 的轉換並沒有切換啊!

發表於: 2007/5/15 14:16
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


雙輸入問題
#1
高級會員
高級會員


查看用戶資訊
想請問我如果用單一輸入ok但是兩個輸入的話卻只有一個可以動作 是因為沒有加入DELAY還是哪裏問題可以指導一下ㄇ??


#include <pic.h> // processor if/def file
#include "cnfig877a.h"
#include "mid_lcd.h"

unsigned char i ;

//***************************
// A/D延遲
//*****************************
void ADdelay(unsigned char i)
{
while(i--);
}

//**********************************
//* Function Prototype Declaration
//**********************************
void Init_IO(void);
void Init_Adc( void );
void Init_Adc_1( void );
void A2D( unsigned char );
void A2D_1( unsigned char );
void LCD_ItoA(unsigned int);
void LCD_ItoA_1(unsigned int);
unsigned char Set_BCD_ASCII(unsigned char);
unsigned char Set_BCD_ASCII_1(unsigned char);

// ================================================================
__CONFIG ( HS_OSC & BODEN_ON & WDT_OFF & CP_OFF & LVP_OFF & DEBUG_ON );

// =================================================================
const char LCD_Msg1[]=" voltage: ";
const char LCD_Msg2[]=" current: ";

unsigned int AD_Temp;
unsigned int AD_Temp_1;
bit DS_Zero_Flag;
bit DS_Zero_Flag_1;

union {
int AD_10bit;

struct
{
char AD_LSB;
char AD_MSB;
}
AD_Byte;
}
AD_Int;

union {
int AD_10bit_1;
struct
{
char AD_LSB_1;
char AD_MSB_1;
}
AD_Byte_1;
}
AD_Int_1;



/*****************************
INITIALIZE I/O PORT
*****************************/

void Init_IO(void)
{
ADCON1=0b00000110; // Disable A/D Function
TRISD=0x00; // Set PortD for Output
PORTD=0x80; // Initila LED display = 0x80
TRISA0=1; // Set RA0 for input
TRISA1=1; // Set RA1 for input

}

/*****************************************
Initialize A/D & Comparator Module
******************************************/

void Init_Adc( void )
{
ADCON0=0b10001001; // Select CH1, A/D on
ADCON1=0b00000010; // AN1 is A/D input
ADFM=0; // Right justified
}
void Init_Adc_1( void )
{
ADCON0=0b10000001; // Select CH0 , A/D on
ADCON1=0b00001110; // AN0 is A/D input
ADFM=1; // Right justified
}
/***********************************
Convert A/D Channel
************************************/

void A2D( unsigned char channel )
{
unsigned char temp; // Temp storage


ADGO = 1; // Initiate conversion on selected channel
while (ADGO) ;
// Poll ADGO bit until it clears, indicating conv. done
AD_Int.AD_Byte.AD_MSB=ADRESH;
AD_Int.AD_Byte.AD_LSB=ADRESL;
temp= ADRESH *256+ ADRESL;
temp = channel >>2; // Shift channel value three bits left
ADCON0 &= 0b11001111; // Clear channel select bits in ADCON0
ADCON0 |= temp; // Logically OR shifted channel value into place in ADCON0
}
void A2D_1( unsigned char channel_1 )
{
unsigned char temp_1; // Temp_1 storage
ADGO = 1; // Initiate conversion on selected channel
while (ADGO) ;
// Poll ADGO bit until it clears, indicating conv. done

AD_Int_1.AD_Byte_1.AD_MSB_1=ADRESH;
AD_Int_1.AD_Byte_1.AD_LSB_1=ADRESL;
temp_1= ADRESH *256+ ADRESL;
temp_1 = channel_1 <<2; // Shift channel value three bits left
ADCON0 &= 0b11000111; // Clear channel select bits in ADCON0
ADCON0 |= temp_1; // Logically OR shifted channel value into place in ADCON0

}

//***************************************
//* Program Main ( ) *
//***************************************
void main(void)
{
Init_IO();
Init_Adc();


OpenLCD();
LCD_Set_Cursor(0,0);
putrsLCD(LCD_Msg1);

Init_Adc_1();
LCD_Set_Cursor(0,1);
putrsLCD(LCD_Msg2);

while(1)
{
A2D(0x00); // Get 10-bit A/D result from CH0
LCD_Set_Cursor(10,0);
LCD_ItoA(AD_Int.AD_10bit);
ADdelay(10);

A2D_1(0x00); // Get 10-bit A/D result from CH0
LCD_Set_Cursor(10,1);
LCD_ItoA_1(AD_Int_1.AD_10bit_1);

}

}

void LCD_ItoA(unsigned int AD_Data)
{
AD_Temp=AD_Data;
DS_Zero_Flag=1;

putcLCD(Set_BCD_ASCII(AD_Data/1000)); // 顯示千位數
AD_Temp=AD_Temp%1000; // 取出百位以後的數

putcLCD(Set_BCD_ASCII(AD_Temp/100)); // 顯示百位數
AD_Temp=AD_Temp%100;

putcLCD(Set_BCD_ASCII(AD_Temp/10)); // 顯示十位數
AD_Temp=AD_Temp%10;

putcLCD(AD_Temp+='0'); // 顯示個位數
}
void LCD_ItoA_1(unsigned int AD_Data_1)
{
AD_Temp_1=AD_Data_1;
DS_Zero_Flag_1=1;

putcLCD(Set_BCD_ASCII_1(AD_Data_1/1000)); // 顯示千位數
AD_Temp_1=AD_Temp_1%1000; // 取出百位以後的數

putcLCD(Set_BCD_ASCII_1(AD_Temp_1/100)); // 顯示百位數
AD_Temp_1=AD_Temp_1%100;

putcLCD(Set_BCD_ASCII_1(AD_Temp_1/10)); // 顯示十位數
AD_Temp_1=AD_Temp_1%10;

putcLCD(AD_Temp_1+='0');

}
unsigned char Set_BCD_ASCII(unsigned char BCD_Data)
{
if (BCD_Data==0)
{
if (DS_Zero_Flag) return ' '; // 居先零抑制
else return '0'; // 顯示一般的零
}
else
{
DS_Zero_Flag=0; // 取消居先零的抑制
return (BCD_Data +='0'); // 並傳回 ASCII Code
}
}
unsigned char Set_BCD_ASCII_1(unsigned char BCD_Data_1)
{
if (BCD_Data_1==0)
{
if (DS_Zero_Flag_1) return ' '; // 居先零抑制
else return '0'; // 顯示一般的零
}
else
{
DS_Zero_Flag_1=0; // 取消居先零的抑制
return (BCD_Data_1 +='0'); // 並傳回 ASCII Code
}
}




發表於: 2007/5/15 13:13
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... ]

教育訓練中心

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