• slider image 442
  • slider image 492
  • slider image 493
  • slider image 494
  • slider image 495
  • slider image 496
  • slider image 491
:::

論壇索引


Board index » All Posts (john0522)




Re: 在範例程式觸控面板控制
#1
新會員
新會員


我把下面的這個範例用PIC18F8722來製作..裡面的ADCFlag不知道是代表什麼意思?我用C18編譯器...請指導一下!!

#include <pic.h>

#define XYSel RA1
#define DIR_XYSel TRISA1
#define X 1
#define Y 0

static bit ADCFlag;
static unsigned char IntCnt,TimerCnt = 158;

void Init(void);
void delay(void);
void delay30us(void);
void delay_charge(void);
void delay_discharge(void);
unsigned long multiplication(unsigned short a,unsigned short b);

/********************************************/
/* 中斷副程式 */
/*PIC只有一個中斷向量位址,也就是只有一個中斷*/
/*副程式,所以可用中斷旗標的檢查來達到多個中 */
/*斷源的目的,在此僅檢查計時中斷. */
/********************************************/
static void interrupt isr(void)
{
if(T0IF){
if(IntCnt == 1){
IntCnt = 0;
ADCFlag = 1;
TMR0 = TimerCnt;
T0IF = 0;
}
else{
TMR0 = TimerCnt;
T0IF = 0;
IntCnt++;

}
}
}

/********************************************/
/* 主程式 */
/********************************************/
void main(void)
{
unsigned short X_pos,Y_pos;
unsigned short Xpos[12],Ypos[12];
unsigned char cnt;
unsigned long x_mul,y_mul;

Init(); // 執行初始設定.

// Status initializing.
RB0 = 1; // 動作時亮燈.
RB2 = 0; // 未觸碰熄燈.
X_pos = 0x0000; // X座標初值為0.
Y_pos = 0x0000; // Y座標初值為0.
XYSel = X; // 初始為X軸.
RB1 = 1; // 開始放電.
ADCFlag = 0; // ADC轉換旗標.
IntCnt = 0; // 中斷次數計數器.
TMR0 = TimerCnt; // 設定初值.


// Main loop.
while(1){

while(!ADCFlag) continue;
ADCFlag = 0;

// Get X coordinate.
delay_discharge();
delay_discharge(); // 放電延遲.
RB1 = 0; // 停止放電.
delay_charge(); // 充電延遲.
for(cnt=0;cnt<12;cnt++){
delay30us(); // CPU要求的延遲.
ADGO = 1; // 開始轉換.
while(ADGO); // 等待轉換完畢.
Xpos[cnt] = ADRESH << 8;
Xpos[cnt] |= ADRESL;
}
XYSel = Y; // 切至Y軸.
RB1 = 1; // 開始放電.

// Get Y coordinate.
delay_discharge();
delay_discharge(); // 放電延遲.
RB1 = 0; // 停止放電.
delay_charge(); // 充電延遲.
for(cnt=0;cnt<12;cnt++){
delay30us(); // CPU要求的延遲.
ADGO = 1; // 開始轉換.
while(ADGO); // 等待轉換完畢.
Ypos[cnt] = ADRESH << 8;
Ypos[cnt] |= ADRESL;
}
XYSel = X; // 切至X軸.
RB1 = 1; // 開始放電.

// Filtering.
if(Xpos[0] == Xpos[1]||Xpos[0] == Xpos[2]||Xpos[1] == Xpos[2]){
if( Ypos[0] == Ypos[1]||Ypos[0] == Ypos[2]||Ypos[1] == Ypos[2]){
if(Xpos[0] == Xpos[1]) X_pos = Xpos[0];
else if(Xpos[1] == Xpos[2]) X_pos = Xpos[1];
else X_pos = Xpos[2];
if(Ypos[0] == Ypos[1]) Y_pos = Ypos[0];
else if(Ypos[1] == Ypos[2]) Y_pos = Ypos[1];
else Y_pos = Ypos[2];
}
else continue;
}
else continue;

////////////////////////////////////////////////////////
// UART(RS232) Transmission
if(X_pos > 928) X_pos = 928;
if(Y_pos > 840) Y_pos = 840;
if(X_pos < 110 || Y_pos < 190){
RB2 = 0;
}
else{
X_pos -= 190;
x_mul = multiplication(X_pos,200);
X_pos = x_mul >> 8;
Y_pos -= 80; // Torlerance adjust.
y_mul = multiplication(Y_pos,92);
Y_pos = y_mul >> 8;
Y_pos -= 25; // Torlerance adjust.
while(TRMT == 0);
TXREG = X_pos >> 8;
while(TRMT == 0);
TXREG = X_pos;
while(TRMT == 0);
TXREG = Y_pos >> 8;
while(TRMT == 0);
TXREG = Y_pos;
RB2 = 1;
}
}
}

發表於: 2008/2/27 14:26
頂部


在範例程式觸控面板控制
#2
新會員
新會員


在範例程式中ADCFlag是代表什麼意思呢?
請指導..謝謝

發表於: 2008/2/26 17:59
頂部


用PIC18F8722做觸控.
#3
新會員
新會員


您好:
我利用PIC18F8722配合microchip網站上的範例程式去做觸控測試,在ADC轉換的時候會卡在 while(!ADCFlag)...如下

ADCFlag用來判斷是否為1,擷取X.Y軸的電壓


while(1){

while(!ADCFlag) continue;
ADCFlag = 0;

發表於: 2008/2/19 16:04
頂部






:::

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... ]

教育訓練中心

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