佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 3780|回复: 12

[更新]PIC MPLAB 问题,新问题在#10

[复制链接]
发表于 3-4-2012 05:49 PM | 显示全部楼层 |阅读模式
本帖最后由 FakeSheep 于 8-4-2012 07:33 PM 编辑

i. 你要想做什么? 你的应用是什么?
我要开始自学PIC用MPLAB IDE, language toolsuite使用Hi-TECH C 或 MPASM assembler 或 PIC C18 Compiler
ii. 你想要拿到什么效果
我要开始自学, 教科书, PIC kits都有了。。就是有很奇怪的问题
iii. 你做了什么
照着教科书上的方法一步一步从new project wizard 到 programming PIC, 过程中都是built successfully, 或 program/verify successed. 看似没问题。。
iv. 你遇到了什么问题。
我试过的方法有很多。PIC Kits是cytron的products。
从cytron的网站下载他们的sample program file,里面有asm或C, 当然还有hexfile
我把他们给的hex file program 进我PIC时 动作没问题。。一切正常。。
问题是我用MPLAB开他们的asm file 或 C file,过后自己在generate新的hex file,再program 去PIC时,就不动作了。。

v. 你用什么MCU?
18F4550
我使用Microchip USB HID Bootloader来program我的PIC。。

vi. 你用什么语言? ASM /C/PICBasic/Keil?Compiler 版本?
ASM and C
vii. 有源码吗? 如是抄来的请注明出处, 请放链接。
http://www.cytron.com.my/viewProduct.php?pcode=SK40-C2&name=40%20pins%20PIC%20Start-Up%20Kit%20Combo%202
下面第三行
viii. 有电路图吗?
没有
ix. 你google 了吗? 你的搜索关键字是什么?
ASM to hex, C to Hex etc
x. 有照片证明你做的东西吗?还是只是概念性的空谈?
影片upload中。。。
xi. 是你自己的问题? 还是你帮人问的? 请说明。
自己的。。。
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 3-4-2012 06:12 PM | 显示全部楼层
本帖最后由 FakeSheep 于 3-4-2012 06:19 PM 编辑

https://rapidshare.com/#!download|287p7|1572402614|2012-04-03_1722.swf|14039
这是我的programming步骤。。是有screen recorder记录的。。应为是swf档。。所以只可以用网盘上载。。youtube不支持swf。。==麻烦高手们了 拜托啦。。还有那个网址要自己全部copy完。。
回复

使用道具 举报

发表于 3-4-2012 06:26 PM | 显示全部楼层
|287p7|1572402614|2012-04-03_1722.swf|14039
这是我的programming步骤。。是有screen recorder记录的。。 ...
FakeSheep 发表于 3-4-2012 06:12 PM

为什么你不去问卖家?
他们会教你的, 你是他们的客户。
回复

使用道具 举报

 楼主| 发表于 3-4-2012 08:30 PM | 显示全部楼层
你觉得我没问?
我两边都有问。。而且我觉得不是产品的问题
应该是generating file时可能我少了什么heading file或之类的,我不知道
当然我也在那边发表同样的问题了。。
不过,既然这边是单晶片分享区就应该不分谁是卖家之类的吧?
我想可能也有别人跟我有同样的问题,我现在问了,以后也方便大家
回复

使用道具 举报

发表于 4-4-2012 08:43 AM | 显示全部楼层
回复 2# FakeSheep

下载了cytron所有的sample code,都没看到的swf影档里的C文件,是你自己写的吗?

post 你的 source code 和hardware schematic上来看看。
回复

使用道具 举报

 楼主| 发表于 4-4-2012 09:02 AM | 显示全部楼层
#include <htc.h>    //まノhtc.h夹繷郎?龟悔?ㄏノpic18F4520.h?
#include "delay.h"    //まノdelay夹繷郎
//========盽计のI/O竲??跋==========
#define ONEMS 100    //?祘Αい?"ONEMS"?﹃?盢?传Θ"100"
//========I/O竲??跋==========
static bit Led        @ ((unsigned)&PORTD*8+0); //??Led?竲&#59284;?PORTD,0
//========&#59268;办跑计??跋==========
unsigned int i;     //??&#59268;办跑计i
//////////////C粂ē磅︽?材??ㄧΑmain//////////////////////////////
void main(void)
{
//=======?﹍?砞﹚跋====================
    TRISD=0b11111110;    //RD,0?块??ㄤ緇?块?
//=======?祘Α跋==秨﹍======================
    while(1)            //ㄏノwhile(1)笷Θ礚絘?伴??
    {
        Led=1;            //盢Led竲块?蔼筿&#59284;?翴獹Led
        DelayMs(ONEMS);    //┑?100ms=0.1s
        Led=0;            //盢Led竲块??筿&#59284;?憾防Led
        DelayMs(ONEMS);    //┑?100ms=0.1s
        i++;            //i=i+1;
    }
//=======?祘Α跋==挡&#59313;======================        
}

抱歉,这个是影片里面的source code,跟cytron给的program差不多一样结果
还有就是这个program是教学书上的例子,不知道为什么我看不到它的中文字。。==
回复

使用道具 举报

Follow Us
 楼主| 发表于 4-4-2012 09:12 AM | 显示全部楼层


Uploaded with ImageShack.us
这是你要的hardware schematic 吗?
回复

使用道具 举报

 楼主| 发表于 4-4-2012 09:20 AM | 显示全部楼层
ok。。我等等再upload用cytron的sample program的影片。。
因为cytron的program可以在他网站拿到。。比较common。。应该方便大家讨论。。
回复

使用道具 举报


ADVERTISEMENT

发表于 4-4-2012 09:35 AM | 显示全部楼层
回复 7# FakeSheep


据我所知很多MCU compiler 的IDE不支持自家IDE或文书处理器以外编写的unicode(中文等。。。文字)。

比方说:在wordpad写的中文字,在MPLAB开出来是乱码。只有在MPLAB写的中文,存档后,再重新开启,都不会显示乱码。

我没有深入研究 MPLAB Hitech C,也比较少用PIC芯片。

对你的问题,我的见解是:
1.科能是MCU 的configuration setting 没有设置好。
  1. //==========================================================================
  2. //        Author                                : CYTRON TECHNOLOGIES SDN BHD
  3. //        Project                                : SK40C sample code for PIC18f4520
  4. //        Project description                : Blink LED1 and LED2 like police car
  5. //
  6. //==========================================================================

  7. //        include
  8. //==========================================================================
  9. #include<p18f4520.h>

  10. //        configuration bit ---- 注意这里的设置
  11. //==========================================================================
  12. #pragma        config OSC = HS                                // HS oscillator
  13. #pragma        config FCMEN = OFF                        // Fail-Safe Clock Monitor disabled
  14. #pragma        config IESO = OFF                        // Oscillator Switchover mode disabled
  15. #pragma        config PWRT = OFF                        // PWRT disabled
  16. #pragma        config BOREN = OFF                        // Brown-out Reset disabled in hardware and software
  17. #pragma        config WDT = OFF                        // WDT disabled (control is placed on the SWDTEN bit)
  18. #pragma        config MCLRE = ON                        // MCLR pin enabled; RE3 input pin disabled
  19. #pragma        config PBADEN = OFF                        // PORTB<4:0> pins are configured as digital I/O on Reset
  20. #pragma        config CCP2MX = PORTC                        // CCP2 input/output is multiplexed with RC1
  21. #pragma        config LVP = OFF                        // Single-Supply ICSP disabled
  22. #pragma        config XINST = OFF                        // Extended Instruction Set

  23. //        define
  24. //==========================================================================
  25. #define        LED1        LATBbits.LATB6
  26. #define        LED2        LATBbits.LATB7

  27. #define        SW1                PORTBbits.RB0
  28. #define        SW2                PORTBbits.RB1

  29. #define        XTAL_FREQ        20MHZ        /* Crystal frequency in MHz */

  30. #define        MHZ        *1000L                        /* number of kHz in a MHz */
  31. #define        KHZ        *1                                /* number of kHz in a kHz */

  32. #if        XTAL_FREQ >= 12MHZ
  33.         #define        DelayUs(x)        { unsigned char _dcnt; \
  34.                                   _dcnt = (x)*((XTAL_FREQ)/(12MHZ)); \
  35.                                   while(--_dcnt != 0) \
  36.                                           continue; }
  37. #else
  38.         #define        DelayUs(x)        { unsigned char _dcnt; \
  39.                                   _dcnt = (x)/((12MHZ)/(XTAL_FREQ))|1; \
  40.                                   while(--_dcnt != 0) \
  41.                                           continue; }
  42. #endif

  43. //        function prototype
  44. //==========================================================================
  45. void init(void);
  46. void DelayMs(unsigned char);

  47. //        global variable
  48. //==========================================================================

  49. //        main function
  50. //==========================================================================
  51. void main(void)
  52. {
  53.         unsigned char i;

  54.         init();                        // initialise PIC
  55.         LED1 = 0;                // off LED1
  56.         LED2 = 0;                // off LED2
  57.        
  58.         while(1)
  59.         {               
  60.                 for(i=8; i>0 ; i--)                // looping for 8 times (4 times blink)
  61.                 {
  62.                         LED1 ^= 1;                        // toggle LED1
  63.                         DelayMs(110);                // delay 110ms
  64.                 }               
  65.                 DelayMs(800);                        // delay 800ms
  66.                
  67.                 for(i=8; i>0 ; i--)                // looping for 8 times (4 times blink)
  68.                 {
  69.                         LED2 ^= 1;                        // toggle LED2
  70.                         DelayMs(110);                // delay 110ms
  71.                 }
  72.                 DelayMs(800);                        // delay 800ms
  73.                
  74.                 while( !SW1 || !SW2 );        // Stop blinking if either SW1 or SW2 is being pressed
  75.         }       
  76. }


  77. //        functions -- 设置 IO的功能(ADC,Digital Input,Digital Output)参考MCU的datasheet吧
  78. //==========================================================================
  79. void init(void)        // initialise function
  80. {
  81.         //tris
  82.         TRISBbits.TRISB0=1;                //configure PORTB I/O direction
  83.         TRISBbits.TRISB1=1;                //configure PORTB I/O direction
  84.         TRISBbits.TRISB6=0;                //configure PORTB I/O direction
  85.         TRISBbits.TRISB7=0;                //configure PORTB I/O direction
  86. }

  87. void DelayMs(unsigned char cnt)        // delay function (mili second)
  88. {
  89.         #if        XTAL_FREQ <= 2MHZ
  90.                 do {
  91.                         DelayUs(996);
  92.                 } while(--cnt);
  93.         #endif
  94.        
  95.         #if    XTAL_FREQ > 2MHZ       
  96.                 unsigned char        i;
  97.                 do {
  98.                         i = 4;
  99.                         do {
  100.                                 DelayUs(250);
  101.                         } while(--i);
  102.                 } while(--cnt);
  103.         #endif
  104. }
复制代码


2.参考cytron的code来改吧。它是用PortB来控制LED闪烁。

你的code是PortD来控制LED闪烁。LED有接到Port D的 bit 0 吗?
回复

使用道具 举报

 楼主| 发表于 8-4-2012 07:31 PM | 显示全部楼层
https://rapidshare.com/#!download|966p8|750226793|2012-04-08_1908.swf|6994
这是我最新upload的swf file的video。。
补充说明
我使用microchip MPASM toolsuite
PIC18F4550
USB bootloader (program/verify software)
影片里的program是我从不同地方参考后改的。。
我是想要控制整个portB的output让LED闪。。就是酱
我想知道为什么我的PIC好像没反应(PIC烧掉除外,因为我换别个chip也是没反应)
回复

使用道具 举报

 楼主| 发表于 8-4-2012 07:34 PM | 显示全部楼层
list        p=18f4550
#include    prlx.asm
#include    P18f4550.INC

DelayD1    equ    0x00
DelayD2    equ    0x01
;--------------------------------------------------
    org        00000h
    goto    Start

    org        00020h
Start:
    movlb    B'00000010'
    movlw    B'01100010'
    movwf    OSCCON
    movlw    B'01111111'
    movwf    TRISB
;------------------------------------------------------
Main:
    movlw    h'ff'
    movwf     PORTB
    call     Delay
    movlw    h'00'
    movwf     PORTB
    call    Delay
    goto    Main

;--------------------------------------------------------
Delay:   
    movlw    H'130';
    movwf    DelayD1;
Del1:   
    movlw    H'ff';
    movwf    DelayD2;
Del2:
    decfsz    DelayD2,1
    goto     Del2
    decfsz    DelayD1,1
    goto    Del1
    return
;-------------------------------------------------------
    End

这是我的源码
回复

使用道具 举报

 楼主| 发表于 22-4-2012 02:11 AM | 显示全部楼层
有没有人能帮我啊~
回复

使用道具 举报

发表于 23-4-2012 08:36 AM | 显示全部楼层
回复 11# FakeSheep

你怎么用 assembly language?

抱歉,帮不上忙,感觉你的assem code 指令运用有问题!

参考下面的贴吧,虽然有问题,毕竟只是个小问题。

关于ADC问题。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 19-4-2024 12:19 PM , Processed in 0.065488 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表