• 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: PIC 18f4520之RB0問題
#7
資深會員
資深會員


查看用戶資訊
RB0有AD的功能
如果沒有改變AD設定的話
預設會是AD PIN
所以當然沒有數位IO的功能了


發表於: 2008/4/27 13:51
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC 18f4520之RB0問題
#6
新會員
新會員


查看用戶資訊
感謝樓上高手的回答,我大概知道您說的意思,但我昨天K完PIC18F4520的DATDSHEET後,真的還是有點有看沒有懂,加上我用C18寫,關於這部分真的還是有點模糊,是否可以請您再給我一些提示呢??拜託您了!!感謝。

發表於: 2008/4/27 11:48
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC 18f4520之RB0問題
#5
資深會員
資深會員


查看用戶資訊
因為你沒先把A/D設定好

請先把書上AD的章節K完再說
Good lucky

發表於: 2008/4/26 14:36
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC 18f4520之RB0問題
#4
新會員
新會員


查看用戶資訊
各位高手您好,這篇問題是小弟麻煩我學長幫我PO的,很感謝2樓的大大幫我回答,但目前有一個問題,小第我依照回覆之程式內容做修改,但卻造成連SW1也無法作DUTY增加與LED燈遞增之動作,是否我修改有誤呢??以下是我修改之內容,還煩請各位幫我看看。
#include <p18f4520.h>
#include <delays.h>
#include <timers.h>
#include <pwm.h>

// 結構位元定義
#pragma config OSC=HS, BOREN=OFF, BORV = 2, PWRT=ON, WDT=OFF, LVP=OFF
// 工作時序頻率定義
#define OSC_CLOCK 10
void delay_ms(long A);
void main (void)
{

unsigned char push_no=1;
PORTD = 0x01;
TRISD = 0;
TRISAbits.TRISA4=1;
TRISBbits.TRISB0=1;
TRISCbits.TRISC2=0;
OpenPWM1(0x9B);
OpenTimer2(TIMER_INT_OFF&T2_PS_1_4&T2_POST_1_1);
while (1)
{
delay_ms(10);
if(PORTAbits.RA4==0)
{
push_no--;
while(PORTAbits.RA4==0);
if(push_no==0)
{
push_no=1;
PORTD++;
}
}
else{
if(PORTBbits.RB0==0)
{
push_no--;
while(PORTBbits.RB0==0);
if(push_no==0)
{
push_no=1; PORTD--;
}
}
}
SetDCPWM1((unsigned int)PORTD<<2);
}
}

void delay_ms(long A) {
long i;
int us2TCY;
us2TCY=(10*OSC_CLOCK)>>2;
for(i=0;i<A;i++) Delay100TCYx(us2TCY);
}
PS.另外還有一個問題想請問各位,由於之前程式是SW1可使DUTY與LED燈達到預設功能,但SW2無法動作,因此我懷疑是否為SW2對應之硬體周邊有問題,所以我將程式中SW1與SW2功能作互換之動作(即SW2作LED燈遞增與DTUY增加),但當按下SW2時發現電路板無動作,照道理來說程式中控制LED遞增與DUTY增加之功能應該沒問題,僅換了不同的開關來作控制,但卻發現電路板都無動作,是否真得是我的電路板出現問題了呢??還是RB0這之腳無法作與RA4一樣作開關檢測的功能??

發表於: 2008/4/26 14:08
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC 18f4520之RB0問題
#3
資深會員
資深會員


查看用戶資訊
吐血,系統不支援tab符號?罷了罷了

發表於: 2008/4/25 19:37
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC 18f4520之RB0問題
#2
資深會員
資深會員


查看用戶資訊
為了測試新工具的自動排縮能力,我特別用它來幫你整理了一下

---
#include <p18f4520.h>
#include <delays.h>
#include <timers.h>
#include <pwm.h>

// 結構位元定義
#pragma config OSC=HS, BOREN=OFF, BORV = 2, PWRT=ON, WDT=OFF, LVP=OFF

// 工作時序頻率定義
#define OSC_CLOCK 10

void delay_ms(long A);

void main (void)
{

unsigned char push_no=1;
PORTD = 0x01;
TRISD = 0;
TRISAbits.TRISA4=1;
TRISBbits.TRISB0=1;
TRISCbits.TRISC2=0;
OpenPWM1(0x9B);
OpenTimer2(TIMER_INT_OFF&T2_PS_1_4&T2_POST_1_1);
while (1)
{
delay_ms(10);
if(PORTAbits.RA4==0)
{
push_no--;
while(PORTAbits.RA4==0);
if(push_no==0)
{
push_no=1;
PORTD++;
}
else{
if(PORTBbits.RB0==0)
{
push_no--;
while(PORTBbits.RB0==0);
if(push_no==0)
{
push_no=1; PORTD--;
}
}
}
SetDCPWM1((unsigned int)PORTD<<2);
}
}
}


void delay_ms(long A) {

long i;
int us2TCY;
us2TCY=(10*OSC_CLOCK)>>2;

for(i=0;i<A;i++)
Delay100TCYx(us2TCY);
}
---

我假設你其它部份沒有問題,比如硬體或週邊設定均正常,這裡只簡單幫你移動個位置

---
while (1)
{
delay_ms(10);
if(PORTAbits.RA4==0)
{
push_no--;
while(PORTAbits.RA4==0);
if(push_no==0)
{
push_no=1;
PORTD++;
}
}
else{
if(PORTBbits.RB0==0)
{
push_no--;
while(PORTBbits.RB0==0);
if(push_no==0)
{
push_no=1; PORTD--;
}
}
}
SetDCPWM1((unsigned int)PORTD<<2);
}
---

程式還有很大的進步空間,自已努力吧


發表於: 2008/4/25 19:33
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


PIC 18f4520之RB0問題
#1
新會員
新會員


查看用戶資訊
各位高手您好:
小弟目前想要撰寫一個簡單的利用開關SW3與SW4控制PWN及LED燈之程式,我利用SW3作為PWM DUTY增加與LED遞增之控制,目前是可行的,但寫到利用SW4作為PWM DUTY減少與LED遞減之控制卻無法實行。小弟的程式如下,因為小弟剛接觸PIC,因此懷疑是否為我的程式觀念有誤,懇請各位高手幫小弟看一下是否有解決方法!!小弟感激不盡。
以下為目前所撰寫之程式碼,其中SW4所對應之RB0腳無法做PWM DUTY減少與LED燈遞減的功能。


#include <p18f4520.h>
#include <delays.h>
#include <timers.h>
#include <pwm.h>

// 結構位元定義
#pragma config OSC=HS, BOREN=OFF, BORV = 2, PWRT=ON, WDT=OFF, LVP=OFF
// 工作時序頻率定義
#define OSC_CLOCK 10
void delay_ms(long A);
void main (void)
{

unsigned char push_no=1;
PORTD = 0x01;
TRISD = 0;
TRISAbits.TRISA4=1;
TRISBbits.TRISB0=1;
TRISCbits.TRISC2=0;
OpenPWM1(0x9B);
OpenTimer2(TIMER_INT_OFF&T2_PS_1_4&T2_POST_1_1);
while (1)
{
delay_ms(10);
if(PORTAbits.RA4==0)
{
push_no--;
while(PORTAbits.RA4==0);
if(push_no==0)
{
push_no=1;
PORTD++;
}
else{
if(PORTBbits.RB0==0)
{
push_no--;
while(PORTBbits.RB0==0);
if(push_no==0)
{
push_no=1; PORTD--;
}
}
}
SetDCPWM1((unsigned int)PORTD<<2);
}
}
}

void delay_ms(long A) {
long i;
int us2TCY;
us2TCY=(10*OSC_CLOCK)>>2;
for(i=0;i<A;i++) Delay100TCYx(us2TCY); }

發表於: 2008/4/25 16:33
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... ]

教育訓練中心

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