Quantcast
Channel: Microchip Taiwan :: 論壇
Viewing full articles (4647 articles)
Browse article index
↧

12F629運作問題 [發表者 cisco6688]

$
0
0
8-bit PIC (請註明使用元件編號):: 12F629運作問題
各位好:

簡單做一電路讓GP0 輸出的RELAY可以動作,但是不管如何燒錄都無法運作。記得幾年前也是這樣,後來換不同英文字母代號的就可以(同樣是12F629 I/P ),這次適用12F629 I/P17F後面的英文代號(I/P[color=990000]17F[/color)是有特別要注意或是在程式部分需設定?

因為是初手,敬請各位高手協助,謝謝!

環境: CCS V5.0.3.5
燒錄器: wellon VP190 (燒錄器晶片選12F629)
程式碼:

#include <12F629.h>
#use delay(clock=4000000)

#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES CPD //No EE protection
#FUSES PROTECT //Code protected from reads
#FUSES NOMCLR //Master Clear pin disabled
#FUSES NOPUT //No Power Up Timer
#FUSES BROWNOUT //Reset when brownout detected 過熱reset


#define O_RELAY PIN_A0
#define I_ON_SW PIN_A1
#define O_ON_LED PIN_A2
#define I_OFF_SW PIN_A3
#define O_OFF_LED PIN_A4
#define I_Trigger PIN_A5
#define Wait10sec 50 // 10s=10000ms->10000/200=50
#define Wait9sec 45 // 9s =9000ms->9000/200=45
#define Wait8sec 40 // 8s =8000ms->8000/200=40
#define Wait7sec 35 // 7s =7000ms->7000/200=35


int1 bRelayON; //boolean
char iTimerCnt,iWaitTime; //,iPTime;


void Timer(void) // delay
{
iTimerCnt=0;
while( iTimerCnt <= iWaitTime)
{
delay_ms (200); //delay 200ms
iTimerCnt++;
}
}

void main()
{

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);//精準度設定
setup_timer_1(T1_DISABLED); //Timer 1 Disable
setup_comparator(NC_NC); //analog 不比較
setup_vref(FALSE );
output_low(O_RELAY); // Let relay OFF
bRelayON = FALSE;

//main loop
while( TRUE )
{

if( bRelayON)
{
if( !input(I_OFF_SW) && input(I_ON_SW) )
{
delay_ms(110);
// Let relay on
bRelayON = FALSE;
output_high(O_OFF_LED);
iWaitTime = Wait8sec;
Timer();
output_low(O_RELAY);
output_low(O_OFF_LED);
//
}

}
else //else b
{
if( !input(I_ON_SW) && input(I_OFF_SW) )
{
delay_ms(110);
// Let relay on
bRelayON = TRUE;
output_high(O_RELAY);
output_high(O_ON_LED);
iWaitTime = Wait8sec;
Timer();
output_low(O_ON_LED);
}
} //else b
delay_ms(2000);

} //while
} //main
↧

Viewing full articles (4647 articles)
Browse article index

Latest Images

Trending Articles



Latest Images