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


Browsing this Thread:   1 Anonymous Users






Re: 16f877a程式問題?
#2
新會員
新會員


查看用戶資訊
或是有辦法在PORTB=之間加個延遲RBarray[0];

再去抓值嗎?

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


16f877a程式問題?
#1
新會員
新會員


查看用戶資訊
就是怎樣再while迴圈裡面多加判斷功能?

功能為:因為目前值到多少會停在那個範圍然後顯示那個陣列裡的值.可是這樣在硬體上值一變就變了.想要做一個就是值變時先停在那個值.然後用清除的功能再重新一次.



大致想法是:
新令一個變數ADRESL=(AD_Data)
然後ADRESL>(AD_Data)的話判斷是或否?
是的話比較
不是的話值再送回ADRESL

以下是程式

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

//**********************************
//* Function Prototype Declaration
//**********************************
void Init_IO(void);
void Init_Adc( void );

void A2D( unsigned char );
void Init_System(void);

// ================================================================
// **** Establish PIC16F877A Configuration Word
// **** == HS Oscillator Mode
// **** == Brown-Out Detect Enabled
// **** == Watch-Dog Timer Off
// **** == Code Protect Off
// **** == Low Voltage Programming Off
// **** == ICD2 Debug Mode On

__CONFIG ( XT_OSC & BODEN_OFF & WDT_OFF & CP_OFF & LVP_OFF & DEBUG_ON );

// =================================================================

const char RBarray[ ]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x79};

unsigned int AD_Temp;

union {
int AD_10bit;
struct {
char AD_LSB;
char AD_MSB;
}AD_Byte;
}AD_Int;

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

void Init_IO(void)
{
ADCON1=0b00000110;

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

void Init_Adc( void )
{
CMCON=0b00000111;
ADCON1=0b00000100;
ADFM=1;
ADCON0=0b10001001;
}

/***********************************
Convert A/D Channel
************************************/

void A2D( unsigned char channel )
{
unsigned char temp;

temp = channel << 3;



ADCON0 &= 0b11000111;
ADCON0 |= temp;

ADGO = 1;
while (ADGO) ;
AD_Int.AD_Byte.AD_MSB=ADRESH;
AD_Int.AD_Byte.AD_LSB=ADRESL;
}

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

while(1)
{
A2D(0);
if ( ADRESL>= 0xFC )
{
PORTB=RBarray[5];
}
else if ( ADRESL>= 0xFA )
{
PORTB=RBarray[4];
}
else if ( ADRESL>= 0xF8 )
{
PORTB=RBarray[3];
}
else if ( ADRESL>= 0xF6 )
{
PORTB=RBarray[2];
}
else if ( ADRESL>= 0xF4 )
{
PORTB=RBarray[1];
}
else if ( ADRESL>= 0xF2 )
{
PORTB=RBarray[0];
}
else
{
PORTB=RBarray[10];
}
}
}

/*****************************
INITIALIZE SYSTEM
*****************************/

void Init_System(void)
{
PORTB = 0x00;
TRISB = 0x00;
};

發表於: 2009/11/26 10:59
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... ]

教育訓練中心

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