Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void configureMicrocontroller () {
- //
- // General Initiate statements
- //
- WDTCTL = WDTPW+WDTHOLD;// Stop Watchdog timer
- P2DIR |= BIT1 | BIT2; // P2 output for LED
- P2IE |= BIT0 | BIT3; // Enable interrupts
- P2IES |= BIT0; // Chance BIT0 to active low
- P3DIR |= WIZ_RESET_PIN | WIZ_SS_PIN; // Set W5200 pins
- P3OUT |= WIZ_RESET_PIN | WIZ_SS_PIN;
- //
- // Initialize SPI
- //
- P3SEL |= 0x0E;
- UCB0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB;
- UCB0CTL1 |= UCSSEL_2;
- UCB0BR0 = 0x00;
- UCB0BR1 = 0;
- UCB0CTL1 &= ~UCSWRST;
- _BIS_SR(GIE);
- }
- void writeToRegister (u_int addr, u_char data) {
- wizSelect(); // Makes SS for W5200 low
- sendReceiveByte(addr >> 8);
- sendReceiveByte(addr);
- sendReceiveByte(0x80);
- sendReceiveByte(0x01);
- sendReceiveByte(data);
- wizDeselect(); // makes SS for W5200 high
- }
- u_char readFromRegister (u_int addr) {
- wizSelect(); // Makes SS for W5200 low
- sendReceiveByte(addr >> 8);
- sendReceiveByte(addr);
- sendReceiveByte(0x00);
- sendReceiveByte(0x01);
- u_char data = sendReceiveByte(0x00);
- wizDeselect(); // makes SS for W5200 high
- return data;
- }
- void writeMultiple (u_int addr, u_int size, u_char *dest) {
- u_int i;
- if (size < 1)
- return;
- wizSelect(); // Makes SS for W5200 low
- sendReceiveByte(addr >> 8);
- sendReceiveByte(addr);
- sendReceiveByte(0x80 | ((size>>8)&0x7F));
- sendReceiveByte(size&0xFF);
- for (i = 0; i < size; i++) {
- sendReceiveByte(dest[i]);
- }
- wizDeselect(); // makes SS for W5200 high
- }
- void readMultiple (u_int addr, u_int size, u_char *dest) {
- int i;
- wizSelect(); // Makes SS for W5200 low
- sendReceiveByte(addr >> 8);
- sendReceiveByte(addr);
- sendReceiveByte((size>>8)&0x7F);
- sendReceiveByte(size&0xFF);
- for (i = 0; i < size; i++)
- dest[i] = sendReceiveByte(0x00);
- wizDeselect(); // makes SS for W5200 high
- }
- u_char sendReceiveByte (u_char data) {
- UCB0TXBUF = data;
- while (!(IFG2 & UCB0TXIFG));
- data = UCB0RXBUF;
- return data;
- }
- void main (void) {
- configureMicrocontroller();
- // Write IP 192.168.1.200
- writeToRegister(0x0009,0xC0)
- writeToRegister(0x000A,0xA8)
- writeToRegister(0x000B,0x01)
- writeToRegister(0x000C,0xC8)
- printf("IP Address is: %d.%d.%d.%d\n",readFromRegister(0x9),readFromRegister(0xA),
- readFromRegister(0xB),readFromRegister(0xC));
- }
Advertisement
Add Comment
Please, Sign In to add comment