• slider image 442
  • slider image 497
  • slider image 498
  • slider image 499
  • slider image 500
  • slider image 502
:::


Browsing this Thread:   1 Anonymous Users




« 1 (2)


Re: 關於16f877a?無法顯示
#2
版主
版主


查看用戶資訊
你有用除錯工具找錯誤嗎?

如果沒有除錯工具,那除錯會有瞎子摸象的感覺,效率很差。

switch(DP_Data/9) 你確定 switch 的判斷式可以用算式嗎?

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


關於16f877a?無法顯示
#1
新會員
新會員


查看用戶資訊
用RA0控制讓七段顯示器顯示1-9

不知道是我不太懂還是哪裡出了問題就是不能顯示

#include <pic.h>    
#include "cnfig877a.h"

//**********************************
//* Function Prototype Declaration
//**********************************
void Init_IO(void);
void Init_Adcvoid );
void A2Dunsigned char );
void Cunsigned char );


// ================================================================
// **** 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 ); 

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



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_Adcvoid )
{
    
CMCON=0b000000111;        // Analog comparator disable
    
ADCON1=0b00001110;        // AN0 is A/D input
    
ADFM=1;                // Right justified
    
ADCON0=0b10000001;         // Selext CH0 , A/D on
}    
                                       
/***********************************
        Convert A/D Channel
************************************/

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
 
    
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;


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


    while(
1)
    {
        
A2D(0);                        
        
C=ADC(AD_Temp);
        
SHOW_DP(C);    
    }
    
}



void SHOW_DP(unsigned int DP_Data)
{
        
AD_Temp=DP_Data;

        switch(
DP_Data/9)                      
    {
        case 
1:
        
PORTB=0x06;
        break;
        
        case 
2:
        
PORTB=0x5b;
        break;
    
        case 
3:
        
PORTB=0x4f;
        break;

        case 
4:
        
PORTB=0x66;
        break;

        case 
5:
        
PORTB=0x6d;
        break;

        case 
6:
        
PORTB=0x7d;
        break;

        case 
7:
        
PORTB=0x07;
        break;

        case 
8:
        
PORTB=0x7f;
        break;

        case 
9:
        
PORTB=0x6f;
        break;


     }

    
}



應該是在 Program Main出問題
請大大多多指教

發表於: 2009/9/23 1:27

Edited by Ryang on 2009年09月23日 11:18:00
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... ]

教育訓練中心

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