http://mbed.org/users/chris/programs/mbedISP/16mhsw with the pull up set for the reset and ISP pins. This program is meant to program the LCP1768 using the ISP interface. The program was originally developed by Chris Styles <http://mbed.org/users/chris/>
main.cpp@0:32b3902b0dca, 2011-11-22 (annotated)
- Committer:
- ethankhall
- Date:
- Tue Nov 22 22:03:30 2011 +0000
- Revision:
- 0:32b3902b0dca
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ethankhall | 0:32b3902b0dca | 1 | #include "mbed.h" |
ethankhall | 0:32b3902b0dca | 2 | |
ethankhall | 0:32b3902b0dca | 3 | DigitalOut led1(LED1); |
ethankhall | 0:32b3902b0dca | 4 | DigitalOut led2(LED2); |
ethankhall | 0:32b3902b0dca | 5 | |
ethankhall | 0:32b3902b0dca | 6 | Serial pc (USBTX,USBRX); |
ethankhall | 0:32b3902b0dca | 7 | Serial target (p28,p27); |
ethankhall | 0:32b3902b0dca | 8 | |
ethankhall | 0:32b3902b0dca | 9 | // We'll drive this low, and then set the as inputs |
ethankhall | 0:32b3902b0dca | 10 | // this mimics an open collector style ouput |
ethankhall | 0:32b3902b0dca | 11 | DigitalInOut reset (p29); |
ethankhall | 0:32b3902b0dca | 12 | DigitalInOut isp (p30); |
ethankhall | 0:32b3902b0dca | 13 | |
ethankhall | 0:32b3902b0dca | 14 | int main() { |
ethankhall | 0:32b3902b0dca | 15 | |
ethankhall | 0:32b3902b0dca | 16 | pc.baud(19200); |
ethankhall | 0:32b3902b0dca | 17 | target.baud(19200); |
ethankhall | 0:32b3902b0dca | 18 | |
ethankhall | 0:32b3902b0dca | 19 | // ISP Input with pullup |
ethankhall | 0:32b3902b0dca | 20 | isp.input(); |
ethankhall | 0:32b3902b0dca | 21 | isp.mode(PullUp); |
ethankhall | 0:32b3902b0dca | 22 | |
ethankhall | 0:32b3902b0dca | 23 | // pulse reset low |
ethankhall | 0:32b3902b0dca | 24 | reset.output(); |
ethankhall | 0:32b3902b0dca | 25 | reset = 0; |
ethankhall | 0:32b3902b0dca | 26 | wait (0.01); |
ethankhall | 0:32b3902b0dca | 27 | |
ethankhall | 0:32b3902b0dca | 28 | // reset input, with pullup |
ethankhall | 0:32b3902b0dca | 29 | reset.input(); |
ethankhall | 0:32b3902b0dca | 30 | reset.mode(PullUp); |
ethankhall | 0:32b3902b0dca | 31 | |
ethankhall | 0:32b3902b0dca | 32 | while (!pc.readable()) {} |
ethankhall | 0:32b3902b0dca | 33 | |
ethankhall | 0:32b3902b0dca | 34 | // pull ISP and nReset low |
ethankhall | 0:32b3902b0dca | 35 | reset.output(); |
ethankhall | 0:32b3902b0dca | 36 | isp.output(); |
ethankhall | 0:32b3902b0dca | 37 | reset = 0; |
ethankhall | 0:32b3902b0dca | 38 | isp = 0; |
ethankhall | 0:32b3902b0dca | 39 | |
ethankhall | 0:32b3902b0dca | 40 | wait (0.1); |
ethankhall | 0:32b3902b0dca | 41 | |
ethankhall | 0:32b3902b0dca | 42 | // Bring target out of reset |
ethankhall | 0:32b3902b0dca | 43 | reset.input(); |
ethankhall | 0:32b3902b0dca | 44 | reset.mode(PullUp); |
ethankhall | 0:32b3902b0dca | 45 | |
ethankhall | 0:32b3902b0dca | 46 | wait (0.1); |
ethankhall | 0:32b3902b0dca | 47 | |
ethankhall | 0:32b3902b0dca | 48 | while (1) { |
ethankhall | 0:32b3902b0dca | 49 | |
ethankhall | 0:32b3902b0dca | 50 | if (pc.readable()) { |
ethankhall | 0:32b3902b0dca | 51 | target.putc(pc.getc()); |
ethankhall | 0:32b3902b0dca | 52 | led1 = !led1; |
ethankhall | 0:32b3902b0dca | 53 | } |
ethankhall | 0:32b3902b0dca | 54 | |
ethankhall | 0:32b3902b0dca | 55 | if (target.readable()) { |
ethankhall | 0:32b3902b0dca | 56 | pc.putc(target.getc()); |
ethankhall | 0:32b3902b0dca | 57 | led2 = !led2; |
ethankhall | 0:32b3902b0dca | 58 | } |
ethankhall | 0:32b3902b0dca | 59 | |
ethankhall | 0:32b3902b0dca | 60 | } |
ethankhall | 0:32b3902b0dca | 61 | } |