![](/media/cache/group/13920082_1104334289609725_7513665353164031743_o.jpg.50x50_q85.jpg)
สัญญาณ sine
Dependencies: mbed
Fork of MCP4922_Sinewave by
main.cpp@6:ea34f3ae69b5, 2016-10-25 (annotated)
- Committer:
- soulx
- Date:
- Tue Oct 25 14:32:24 2016 +0000
- Revision:
- 6:ea34f3ae69b5
- Parent:
- 5:c4a38038ab44
updata mbed
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 | { |
soulx | 2:2244c8986987 | 11 | MCP.frequency(20000000); |
jf1vrr | 0:5737b1972549 | 12 | |
soulx | 2:2244c8986987 | 13 | uint16_t i=0; |
soulx | 2:2244c8986987 | 14 | uint8_t state=0; |
soulx | 2:2244c8986987 | 15 | while(1) { |
soulx | 5:c4a38038ab44 | 16 | if(i < 0x0FFE) { |
soulx | 2:2244c8986987 | 17 | i++; |
soulx | 5:c4a38038ab44 | 18 | |
soulx | 5:c4a38038ab44 | 19 | } else { |
soulx | 2:2244c8986987 | 20 | i=0; |
soulx | 2:2244c8986987 | 21 | state = ~state; |
soulx | 2:2244c8986987 | 22 | } |
soulx | 5:c4a38038ab44 | 23 | |
soulx | 5:c4a38038ab44 | 24 | if(state ==0) { |
soulx | 2:2244c8986987 | 25 | MCP.writeA(i); |
soulx | 5:c4a38038ab44 | 26 | } else { |
soulx | 5:c4a38038ab44 | 27 | MCP.writeA( ((~i)+1)&0x0FFF); |
soulx | 5:c4a38038ab44 | 28 | } |
soulx | 5:c4a38038ab44 | 29 | wait_us(1); |
soulx | 2:2244c8986987 | 30 | } |
jf1vrr | 0:5737b1972549 | 31 | } |