顯示具有 MCU 標籤的文章。 顯示所有文章
顯示具有 MCU 標籤的文章。 顯示所有文章

2017年10月18日 星期三

[MCU]PIC18F45K20 Demo board LED Example

手邊有一組 PICkit 44-Pin Demo Board (PIC18F45K20)


這塊版子的LED在RD0~RD7

可變電阻(右上方)接在RA0

Switch Button(右下方)接在RB0

程式碼如下
#pragma config FOSC = INTIO67    // FOSC = INTIO67 Internal oscillator block
#pragma config WDTEN = OFF, LVP = OFF    // LVP = OFF Single-Supply ICSP disabled
                                         //WDTEN = OFF Watch dog timer is always disabled. SWDTEN has no effect.
 #include "p18f45k20.h"   //inclue this mcu header
 
 void delay();   
 //delay function   
 void delay() {      
    int counter = 0;   
    for (counter = 0; counter<1000; counter++);    
 }   
 void main(void) {      
    int dummy = 0;   
    /*init the RA0 as analog input*/   
    TRISA = 0x1; // set potentiometer at porta as input (only set port A0)    
    ANSELbits.ANS0 = 1; // set RA0 to analog (=1, 0 = digital) -> this is important to potentiometer  at RA0      
    ADCON0bits.ADON = 1; // activate A/D unit   
    /*init the RB0 as digital input*/   
    TRISB = 0x1; // set bit0 of portb to input because there is the push button at RB0      
    ANSELHbits.ANS12 = 0; // set RB0 to digital (=0, 1= analog) -> this is important to read button at RB0   
    /*init the RD0..RD7(PORTD) as digital output*/   
    TRISD = 0; // all bits of portd are set 0 as output      
    PORTD = 0; // deactivate all led's   
                                                                                                                                                                 
    while (1) {          
       if (PORTBbits.RB0 == 0) { //check if button is pressed (=0, 1= not pressed)                          
          ADCON0bits.GO_DONE = 1; // start A/D convert              
          while(ADCON0bits.GO_DONE != 0); // wait till A/D convert done               
          dummy = ADRESH; // copy A/D result (high part) to leds -> dummy variable is only for better debugging              
          PORTD = dummy;          
       } else {              
          PORTD = PORTD<<1; // move set led   
          if (PORTD == 0) {    
             PORTD = 0x1; // if all led's off activate one   
          }          
       }   
       delay();      
    }       
 }   
 



程式碼內容主要為

config
設定使用內建震盪器、關閉看門狗

pin define

設定RA0為類比輸入
RB0為類比輸入
RD0~7為輸出

function
若switch button沒有按下,則執行跑馬燈,

若按下則讀取RA0的類比輸入並透過LED
顯示數值。












一開始遇到的困難是程式build success,按燒錄後卻沒有任何反應,

以下有二個小心得:

(1) 燒錄時Pickit 3要供電3.25V
(2)必須按下Run Project,單獨program的話,只會在燒錄過程中供電,燒完就沒電了,
當然不會亮囉。

晚安囉~

參考資料:

2016年11月11日 星期五

[MCU]PIC 18F4550 燒錄DIY

網路上看到一個PIC 18F4550燒錄電路,想說來焊一下好了。


焊接電路圖請參考,不過我供電的部份改用DC母座

http://kl1331.pixnet.net/blog/post/140584684-pic18f4550-programing-with--pickit3


這個燒錄電路也是需要搭配PICKIT3 才能用的。





























零件表

KT-10 電木板                    NT  10

OK 線一捲                        NT 35 (其實只用到一點點)

電源2.1母頭含線             NT 12

1/2 W 10K歐姆電阻        NT  1

40-pin DIP ZIF sockets   NT  180

8 PIN  90度排針座          NT   2

---------------------------------------------
合計                                 240


實際測試,可以讀到ID



2016年10月31日 星期一

[MCU] PIC 24FJ64GA002 燒錄電路

看到"從PIC開始! RC伺服機機器人製作入門"上的燒錄電路,動作DIY一下。

(由於不確定書中電路圖是否能PO,所以只PO成品)


























正面照1


正面照2



























背面照(焊接技術不好傷眼,多包函)


零件表:

KT-10 電木板                    NT  10

OK 線一捲                        NT 35 (其實只用到一點點)

電源2.1母頭含線             NT 12

1/2 W 10K歐姆電阻        NT  1

10 uF 積層陶瓷電容器    NT  38

28-pin DIP ZIF sockets   NT  135

8 PIN  90度排針座          NT   2

---------------------------------------------
合計                                   233



讀取ID成功



























心得:

(1)使用PICKET 3  建議供電3.3V。

(2)10 uF 積層陶瓷電容器真難買,長明街找了3家都沒有賣,

     最後在RS網站上購買到。

https://twcn.rs-online.com/web/p/ceramic-multilayer-capacitors/8118373/


參考連結

http://shop.robotkingdom.com.tw/books/pic-rc.html

從PIC開始! RC伺服機機器人製作入門