Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of MCP4922_Sinewave by
main.cpp@4:bf75b2a7d8b5, 2015-11-05 (annotated)
- Committer:
- PKnevermind
- Date:
- Thu Nov 05 08:06:13 2015 +0000
- Revision:
- 4:bf75b2a7d8b5
- Parent:
- 3:863a9b7d417a
...
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| soulx | 2:2244c8986987 | 1 | |
| jf1vrr | 0:5737b1972549 | 2 | #include "mbed.h" |
| jf1vrr | 0:5737b1972549 | 3 | #include "MCP4922.h" |
| jf1vrr | 0:5737b1972549 | 4 | |
| soulx | 2:2244c8986987 | 5 | MCP4922 MCP(SPI_MOSI, SPI_SCK,SPI_CS); // MOSI, SCLK, CS |
| jf1vrr | 0:5737b1972549 | 6 | |
| jf1vrr | 0:5737b1972549 | 7 | |
| jf1vrr | 0:5737b1972549 | 8 | /**** Main Function ***/ |
| soulx | 2:2244c8986987 | 9 | int main(void) |
| soulx | 2:2244c8986987 | 10 | { |
| PKnevermind | 4:bf75b2a7d8b5 | 11 | MCP.frequency(10000000); |
| PKnevermind | 4:bf75b2a7d8b5 | 12 | |
| PKnevermind | 4:bf75b2a7d8b5 | 13 | uint16_t i=0; |
| PKnevermind | 4:bf75b2a7d8b5 | 14 | uint8_t state=0; |
| soulx | 2:2244c8986987 | 15 | while(1) { |
| PKnevermind | 4:bf75b2a7d8b5 | 16 | if(i < 0x0FFF) |
| PKnevermind | 4:bf75b2a7d8b5 | 17 | { |
| PKnevermind | 4:bf75b2a7d8b5 | 18 | i++; |
| PKnevermind | 4:bf75b2a7d8b5 | 19 | |
| PKnevermind | 4:bf75b2a7d8b5 | 20 | } |
| PKnevermind | 4:bf75b2a7d8b5 | 21 | else |
| PKnevermind | 4:bf75b2a7d8b5 | 22 | { |
| PKnevermind | 4:bf75b2a7d8b5 | 23 | i=0; |
| PKnevermind | 4:bf75b2a7d8b5 | 24 | state = ~state; |
| PKnevermind | 4:bf75b2a7d8b5 | 25 | } |
| PKnevermind | 4:bf75b2a7d8b5 | 26 | |
| PKnevermind | 4:bf75b2a7d8b5 | 27 | if(state ==0) |
| PKnevermind | 4:bf75b2a7d8b5 | 28 | { |
| PKnevermind | 4:bf75b2a7d8b5 | 29 | MCP.writeA(i); |
| PKnevermind | 4:bf75b2a7d8b5 | 30 | } |
| PKnevermind | 4:bf75b2a7d8b5 | 31 | else{ |
| PKnevermind | 4:bf75b2a7d8b5 | 32 | MCP.writeA( ((~i)+1)&0x0FFF); |
| PKnevermind | 4:bf75b2a7d8b5 | 33 | } |
| PKnevermind | 4:bf75b2a7d8b5 | 34 | wait_us(20); |
| soulx | 2:2244c8986987 | 35 | } |
| jf1vrr | 0:5737b1972549 | 36 | } |
