编译器
- 16F及以下 好像microchip没有推出相应的C编译器,开发环境中显示都没有,推荐用第三方的HI-TECH
- 18F hi-tech的PICC18或者microchip的MCC18
- 16位24系列,dsPIC30/33的用Microchip的MCC30 C30
- 32位的用
Hi-tech HI-TECh是首选,编译效率高,连官方都推荐,只不过商业软件要花钱 已经被microchip收购 hi-tech还是采用默认的路径比较保险 Demo Download 2008年2月16日 周六下午1:20 发件人: “HI-TECH Software” download-followup@htsoft.com 将发件人添加到地址簿 收件人: wly_1@yahoo.com.cn Thank you for downloading the evaluation version of our * PICC-18 STD Compiler (WINDOWS) We hope it offered you an insight of how HI-TECH C® compilers can help you write more compact, efficient embedded code. If you have any queries about the evaluation software, please do not hesitate to contact your nearest HI-TECH Software distributor by first visiting www.htsoft.com/portal/distributors. Team HI-TECH Sales Team Ph: +61 7 3722 7777 Email: sales@htsoft.com. Technical Support Team Ph: 866 794 8324 (toll free within USA) / +61 7 3722 7783 Email: support@htsoft.com ——————————————————————– HI-TECH Software will be exhibiting at the Embedded Systems Conference Silicon Valley, April 15-17 at booth 935. You can register to attend the conference at https://www.cmpevents.com/ESCw08/a.asp?option=B. 标记这封邮件 Re: i have a problem… - SC38362-39711 2008年5月16日 周五上午5:50 发件人: “support@htsoft.com“ support@htsoft.com 将发件人添加到地址簿 收件人: “wanglingyu” <wly_1@yahoo.com.cn>, “wanglingyu” <wly_1@yahoo.com.cn> Hi, >hi,sorry to bother you >why 聽picc-18 pro doesn’t support bank keywords?while it seems that the std version dose >i used bank1 to put the a variable into bank1,yet it is still in bank0 Neither the PICC-18 PRO, nor STD, compiler directly support the bank keywords. These keywords are accepted without error to allow code to be migrated from PICC baseline/midrange devices, but the keywords have no effect. I recommend not trying to place variables at particular memory locations, but if you must do this, then make the variable absolute (@ address), at an address that is within bank 1. See the manual for more details. Regards, Jeff. 子函数过大,会出现问题 PICC 决定了C 原程序中的一个函数经编译后生成的机器码一定会放在同一个程序页面 内。中档系列的PIC 单片机其一个程序页面的长度是2K 字,换句话说,用C 语言编写的任 何一个函数最后生成的代码不能超过2K 字。一个良好的程序设计应该有一个清晰的组织结 构,把不同的功能用不同的函数实现是最好的方法,因此一个函数2K 字长的限制一般不会 对程序代码的编写产生太多影响。如果为实现特定的功能确实要连续编写很长的程序,这时 就必须把这些连续的代码拆分成若干函数,以保证每个函数最后编译出的代码不超过一个页 面空间。 MCC18 参考资料 C18.pdf 这样访问位: INTCONbits.GIE = 1; INTCONbits.PEIE = 1; 这样声明中断 #pragma code highinterrupt=0x0008 void high_vector (void) { _asm goto button _endasm } #pragma code /* low priority interrupt dispatch function. * FIXME: This function must be located at the low * priority interrupt vector. */ #pragma code lowinterrupt=0x0018 void low_vector (void) { _asm goto tmr2 _endasm } #pragma code #pragma interruptlow tmr2 void tmr2 (void) { } #pragma interrupt button void button (void) { } MCC30 寄存器调用方式变化了 原来RA0,现在需要_RA0 中断声明方式变化了
MPLAB IDE
定制窗口的方法 找到窗口,使其显示标题栏浮动在外面,右键点击,选择Dockable,然后拖动 当窗口找不到其标题栏时,可windows中选择一种窗口排列方式即可 运用: 让左侧显示文件右侧显示代码,让右侧下方显示watch窗口、编译信息等 F9 RUN一次 STEP INTO F7 STEP OVER F8 STEP OUT BREAKPOINTS F2 ref 一些技巧 1.打开 edit\properties菜单,选C File Types,取消Double click toggles breakpoit即可,双击选取单词,再次双击选取整行 2.右键点击要停靠的窗口的标题栏,选定Dockable,即可实现窗口停靠 3.打开 edit\properties菜单,选general标签,选中use tabedd window, 即可使打开地多个源文件,显示在一个标签上,方便源文件切换 4.打开 edit\properties菜单,选C File Types标签,选中auto indent, 即可实现书写源文件的到换行的时候,自动tab对其 5.打开 edit\properties菜单,选C File Types标签,选中Enable code folding, 即可实现代码折叠功能 6.打开 edit\properties菜单,选Tool tips标签,选中AutoComplete下面的几个选项, 有时作为debugger时导致界面错乱–>编译的时候拔下烧录器
MPLAB IDE出现问题解决办法
//有时候出现异常关闭,有的窗口比如输出窗口,跑到显示界面的一角等等异常情况 //遇到这些情况有时候自己一点点手动调整界面的窗口解决了 //曾经尝试过一个办法比较好,删除掉workspace文件,然后打开project文件,然后将工作区另存为其他名称的 //曾经遇到打开项目自动关闭的情况,打开以前可以的也不行了,根据网上搜索到中文资料新建一个账号确实可以,但是我想要根本解决,又搜索到英文资料最终解决: MPLAB IDE closes automatically when I run it. try this utility 1st: C:\Program Files (x86)\Microchip\866\MPLAB IDE\Utilities\SetDefaultMPLABStartup
MPLAB X IDE
新的开源开发环境 曾经在虚拟机里进行了尝试,竟然要求路径中不能含有空格,这样以前的项目不能直接迁移过来了,算了
烧写器
最常用的ICD2/3 参考资料 ICD2.PDF 个人见解:ICD3 和ICD2没什么太大的变化,原装的ICD2 用是18F4550 虽说是用USB的单片机,但从速度上来说,它和232的差不了多少, 所谓的高速USB可能也就是现在网上流传的ICD2.5 的速度吧,再快也没什么用,因为我们的单片机才跑到多少MHz,所以 ICD2.5不会比 ICD3差多少!而且现在个人做的ICD2 ICD2.5 性价比相当高! ICD2速度慢在于PIC16F877A,与USB速度关系不大,如果能CPU能达到FULL SPEED的速度,那CPU要达到12*4=48MISP,同样16F877A就要达到48*4=192MHZ的速度才能发挥到USB FULL SPEED,你们看一下J—LINK同样是USB FULL SPEED那会速度慢,我个人认为ICD3(USB high speed+FPGA)不如PIC32带USB的单蕊片方案(象PICKIT2)
常见问题
连接问题 可以插拔多连接几次 确保驱动安装正确 cannot validate a target device cannot validate的影响 错误型号的芯片都烧录进去了 连接错误,目标芯片不对,选错型号,芯片损坏… 连接有没有断线 verify failed ICD0161: Verify failed (MemType = Program, Address = 0x0, Expected Val = 0x40200, Val Read = 0x0) ICD0275: Programming failed. MPLAB ICD 2 ready for next operation 但如果芯片中已有配置字是内部晶振和内部复位的程序,且程序中有对ICSPCLK和ICSPDAT管脚的操作,再次编程就会有校验失败的错误提示。这是因为当使用内部晶振和内部复位时, ICD2一旦和目标板相连,目标芯片即已工作,ICD2对ICSPCLK和ICSPDAT的控制被目标芯片对这两脚的操作打乱,故而进不了编程模式。这时该考虑其他编程工具, 或者在程序开头加2ms以上延时, 保证芯片在真正执行程序前进入编程模式。 no VDD ICDWarn0021: No Vdd voltage detected at Target. Continue with operation? (OK, Cancel) A debug operation has been initiated and MPLAB ICD 2 has determined that the target device has no Vdd power. You should check that power is supplied to the target, and that MPLAB ICD 2 and the target are connected correctly. Selecting OK continues with the debug operation despite the lack of power. Cancel aborts the operation. 电压问题 有时不支持从ICD2供电,比如3.3v系统? 有时不建议用4.5v以下的 At Vdd < 4.5v, the part cannot be bulk erased, so it has to be row erased. Row erase can be used on program memory, but not on configuration memory (where user ID resides.) cannot erase ID memory at VDD<4.5V MPLAB ICD 2能在目标PICmicro单片机VDD电平为2V到5.5V的范围内工作。 ICDWarn0020: Invalid target device id (expected=0x71, read=0x0) ICDWarn0020: Invalid target device id (expected=0x71, read=0x0) 有的器件行有的不行的情况!!?? 有ICD2,有的器件可以没有什么问题地正常烧录,有的会cannot validate a target device甚至verify failed 进不了debugger模式 晶振工作 没有代码保护 等 PICKit2 1—-/RST –VDD –VSS –PGD –PGC 6—-
PICkit 3
是MICROCHIP为了促进PIC32的推广而推出的最新的低端在线调试器,支持从8位到32位的PIC MCU及DSC
批量烧录工具PM3
参考资料: MPLAB PM3 EN.pdf MPLAB PM3.pdf PM3_ICSP_DesignGuide(DS51474a).pdf ETN26_MPLAB PM3 VPP SLEW RATE.pdf PM3 ICSP RJ11 Adapter.pdf 三种使用方法 1.配合MPLAB IDE ,用插座或ICSP 选PM3 settings选USB或串口 2.脱机使用 读取器件 然后就可以烧录其他的了 通过MPLAB IDE下载 烧录后就残留了还是 transfer to PM3?transfer to PM3是只hex还是环境也保存了? 选器件后可烧录等操作 3.使用存储卡,建立PM3环境存储到SD卡中,然后载入环境,比较适合寄给第三方生产的情况 保存环境,载入环境,也可通过IDE访问和管理环境 卡是自带MMC?支持SD卡 自己做转接板 14芯,然后做一个目标接口,对应引脚顺序可按PICkit的或者自定义的 其中有状态指示信号 PASS FAIL 有GO接快捷操作,比如一键烧录验证 这些比较适合生产实际情况 如果不能正常烧录,可考虑一个pdf中所介绍的隔离 MCLR到复位电阻电容之间串联一个电阻,如果PGD PGC外接使用,可串联电阻 关于LVP: 一般不使用,ICD不支持LVP 使用LVP需要器件也支持 正常VDD app 5V Vdd min 3v Vdd max 5.5v VDD Nom 5V VPP 13.25 PM3中可通过显示菜单设置ICSP供电方式,已经选择是否LVP 其他 对于ICSP,除了VDD和VSS引脚之外, 您还必须连接AVDD和AVSS引脚,这样才能 对器件进行编程。 有的单片机有AVDD AVCC 是AD转换等用的 AVDD和 AVSS引脚是模拟的电源和地,如果你没有用到A/D的话,最好将AVDD和 AVSS引脚接到VDD和 VSS引脚。 关于接线: 如果目标板是5芯单列插针(或直接焊盘孔),请直接做一个5芯插孔的插头(或插针); 请参考一个pdf附件和PM3用户指南 ICSP连接器在安装插座模块的位置下方!! PM3 —DB9/USB—->PC —–>插座直接放上芯片 适用于器件没有焊接到电路板上的情况 或者—–>ICSP线 适用于器件已焊接到电路板上的情况 1.作为ICD2一样的编程器使用 2.脱机使用,将hex下载到里面 LCD显示菜单 也可programmer中将环境存储到存储卡上,再装在环境 手册上缺陷: 没有说明另一端情况 PM3 的 ICSP 我試過了 , 很正常的 : 只要把 (1) CLK , (3) DATA , (7) VPP , (9) VDD , (13) GND 連接至 Target Board 就可以了. Hello Cynthia, Thank you for your quick reply. I have read the PM3 user guide, and I understand the specification of the 14-pin header on the PM3. But the user guide does not tell me what, if anything, is on the other end of that cable. Is there a connector on the other end of the cable? If so, what type of connector is it? Thanks again, Steve Only one end of the PM3 cable has a connector. Although this may appear to be a nuisance at first, it is not that bad if you connect the individual wires one-at-a-time to the PM3 socket and use the end with connector to plug into your target board, assuming that your target board has a 14 pin socket. You will only need to connect to PM3 once but many times to target board, so it is sensible to connect “loose” wires to PM3 and leave them connected. (If you are using Low Voltage programming, you will only need to connect CLK (violet pin 1), DATA (orange pin 3), LVP/Clock (white pin 5) and Gnd (black pins 13 and 14) to PM3 socket and possibly power) ICSP线缆连接PM3一端的是14脚的,另一端呢? 有卖Accessory: AC164111 PM3 ICSP RJ11 Adapter 对于ICSP,除了VDD和VSS引脚之外, 您还必须连接AVDD和AVSS引脚,这样才能 对器件进行编程
第三方工具
贝能 高拓 希尔特 编程 参PIC单片机晶振接法.pdf 编程 五条线 ——-晶振问题 常规的: 1.从OSC1 OSC2接外部晶振 电容 适用于LP、XT和HS模式 2.选内部晶振 从OSC1输入一个外部信号,而OSC2什么也不用接 同样适用于LP、XT和HS模式 ——-配置 EC模式需要的 “振荡器,时钟电路:就是说需要外部有一个产生时钟的电路,以提供系统所需要的时钟。 HS,LP,XT需要的”谐振器,晶振:就是说只需要在外部提供一个晶振,当然可能还需要电容。 选HS,LP,XT又有什么区别:主要是用于不同的频率,200K以下用LP,200K - 4M用XT,2M以上用HS,当然这也是一般用法,具体问题具体分析。 一般都是先进行4分频的,也就是说接16M的晶振,内部的工作频率也就是4M,执行一条指令需要0.25us。