24
PC to Pic Microcontroller by Bruce Misner This project is intended to show several aspects of how to communicate between your PC and a Pic microcontroller. The main focus is the communication itself. We will communicate via a RS232 link using the serial port of the PC and UART of the Microcontroller. The code on the PC side is written in C# and the code on the Pic side is written with the HiTech C that comes bundled with MPLAB. The communication link has to pass through an interface to convert the serial information from TTL levels to RS232 levels. The goal of the project is to have the PC request certain data from the controller as to perform simple data acquisition and command the controller to provide certain output. On the controller side I tried to give examples of most common types of I/O that are available on the device. The inputs that are demonstrated are simple digital input through Port B and analog input through Ports A and E. The outputs provided are digital out through Port D and PWM output through bits 1 and 2 of Port C. he UART connections are also made through Port C on bits 6 and 7. The following schematic shows everything gets wired together. This includes the eight DIP switches on Port B to provide the digital input, the LED board that consists of eight LEDs to show a change in digital output on Port D. It shows that one of the PWM outputs drives an H-bridge board that in turn drives a DC motor and a variable DC supply that provides an analog input on Port A.

PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

Embed Size (px)

Citation preview

Page 1: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

PC to Pic Microcontroller by

Bruce Misner

This project is intended to show several aspects of how to communicate between your PC and a Pic microcontroller. The main focus is the communication itself. We will communicate via a RS232 link using the serial port of the PC and UART of the Microcontroller. The code on the PC side is written in C# and the code on the Pic side is written with the HiTech C that comes bundled with MPLAB. The communication link has to pass through an interface to convert the serial information from TTL levels to RS232 levels. The goal of the project is to have the PC request certain data from the controller as to perform simple data acquisition and command the controller to provide certain output.

On the controller side I tried to give examples of most common types of I/O that

are available on the device. The inputs that are demonstrated are simple digital input through Port B and analog input through Ports A and E. The outputs provided are digital out through Port D and PWM output through bits 1 and 2 of Port C. he UART connections are also made through Port C on bits 6 and 7.

The following schematic shows everything gets wired together. This includes the

eight DIP switches on Port B to provide the digital input, the LED board that consists of eight LEDs to show a change in digital output on Port D. It shows that one of the PWM outputs drives an H-bridge board that in turn drives a DC motor and a variable DC supply that provides an analog input on Port A.

Page 2: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

On the PC side there is no real hardware required except the MAX232 board which does the conversion between the TTL levels of the microcontrollers UART I/O to the RS232 levels accepted by COM1 port on the PC. The only hardware is the cable to go from COM1 port to the MAX232 board. The cable is simply a three wire connection that connects ground, pin 5 on the DB9 connector for COM1 to the ground on the MAX232 board. Pin 2 on the DB9 connector is receive and it is connected to pin 14 on the MAX232 chip. Pin 3 is transmit and it is connected to pin 13 on the MAX232 chip. The following schematic shows the MAX232 board and its connections.

Page 3: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

The serial communication has been set up to use 9600 baud, 1 stop bit and no parity. It is to transmit in a high speed asynchronous mode with no handshaking. This means that the UARTs on both sides continuously sample the receive lines waiting for a start bit. On the Pic side the following code configures the UART to provide this service. SPBRG = 64; // 9600 baud high speed RCSTA = 0x90; // sp enabled 8 bit async high speed TXSTA = 0x24; // 8 bit async high speed It is simply the three registers on the Pic that configure the UART. The transmit portion of the code is very simple. By simply placing the 8 bits of data in the TXREG and waiting for the TXIF flag bit to return to its normally high state your will have been transmitted. The receiving of data is a little more complicated in that it uses an interrupt to signal that data is arriving. In order to decipher my code the other thing you have to know is my little protocol that I set up in order to transfer the information back and forth between the two systems. I have to admit I have not been very consistent with my protocol but it all works. It is essentially a 6 byte string terminated with a dollar sign. Some commands do not require the full six bytes but are still terminated by the dollar sign. The other inconsistency is that I sometimes use hex and sometimes decimal to transfer values.

Page 4: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

This is the complete Pic code /* Include files used */ #include <pic.h> /* Global Variables */ int advalue,strdone,tempcount,temph; char recmess[6],tempchar; char* rc; /* Subroutine section init() - initializes registers for funtionality initpwm() - sets up the PWM registers for operation */ void init(void) { TRISC = 0x80; // Port C output except RC7 RX TRISA = 0xff; // Port A input TRISE = 0x07; // PORT E input TRISD = 0; // Port D output TRISB = 0xff; // Port B input PORTD = 0; // Initialize Port D to zero PIR1 = 0; // Clear peripheral interrupt flags INTCON = 0xc0; // GIE and PEIE on PIE1 = 0x20; // RCIE on ADCON1 = 0; // Left justified, all inputs analog ADCON0 = 0x89; // Fosc/32, channel 1, A/D on SPBRG = 64; // 9600 baud high speed RCSTA = 0x90; // sp enabled 8 bit async high speed TXSTA = 0x24; // 8 bit async high speed } void initpwm() { PR2 = 0xff; // period register CCPR1L = 0x0; CCP1X = 0; // least sig. bits of duty cycle CCP1Y = 0; CCP1M3 = 1; // for PWM mode

Page 5: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

CCP1M2 = 1; // for PWM mode CCPR2L = 0x0; CCP2X = 0; // least sig. bits of duty cycle CCP2Y = 0; CCP2M3 = 1; // for PWM mode CCP2M2 = 1; // for PWM mode T2CKPS1 = 1; // prescale timer 16 TMR2ON = 1; // turn timer on } // // // Interrupt Service Routine // // looking for RX interrupt // // static void interrupt isr(void) { if (RCIF) // test for RC interrupt flag { tempchar = (char)RCREG; // get char recmess[tempcount] = tempchar; // save in char array tempcount++; // increment counter if (tempchar == '$') // test for last char { strdone = 1; // set flag for string complete tempcount = 0; // zero counter } RCIF = 0; // clear interrupt flag } } // // subroutine to send a string to the PC // void sendstring(char* c) { int i; i = 0; // i is a counter

Page 6: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

while (c[i] != '$') // test for end of string { TXREG = c[i]; // send char to PC i++; // increment counter while (!TXIF); // wait for char to be sent } TXREG = '$'; // send end of string char while (!TXIF); // wait for char to be sent } // // convert integer to string in decimal format // void convcount(void) { int temp,temp1,temp2; temp = tempcount/100; // get hundreds recmess[0] = 0x30+temp; // convert to ascii char temp1 = (tempcount - temp * 100)/10; // get tens recmess[1] = 0x30+temp1; temp2 = (tempcount - temp * 100-temp1*10); // get ones recmess[2] = 0x30+temp2; recmess[3] = '$'; // add string terminator } // // set a/d port and get sample // void a2dset() { int i; for (i=0;i<10;i++); // settling time for amux GODONE = 1; // start conversion while (GODONE); // wait for conversion to end tempcount = ADRESH; // save ms 8 bits to tempcount convcount(); // convert binary to string sendstring(rc); // send string to PC } //

Page 7: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

// convert string to hexidecimal // void stoh() { if (recmess[3] == '0') temph = 0; if (recmess[3] == '1') temph = 0x10; if (recmess[3] == '2') temph = 0x20; if (recmess[3] == '3') temph = 0x30; if (recmess[3] == '4') temph = 0x40; if (recmess[3] == '5') temph = 0x50; if (recmess[3] == '6') temph = 0x60; if (recmess[3] == '7') temph = 0x70; if (recmess[3] == '8') temph = 0x80; if (recmess[3] == '9') temph = 0x90; if (recmess[3] == 'a') temph = 0xa0; if (recmess[3] == 'b') temph = 0xb0; if (recmess[3] == 'c') temph = 0xc0; if (recmess[3] == 'd') temph = 0xd0; if (recmess[3] == 'e') temph = 0xe0; if (recmess[3] == 'f') temph = 0xf0; if (recmess[4] == '0') temph |= 0; if (recmess[4] == '1') temph |= 0x01; if (recmess[4] == '2') temph |= 0x02; if (recmess[4] == '3') temph |= 0x03; if (recmess[4] == '4') temph |= 0x04; if (recmess[4] == '5') temph |= 0x05; if (recmess[4] == '6') temph |= 0x06; if (recmess[4] == '7') temph |= 0x07; if (recmess[4] == '8') temph |= 0x08; if (recmess[4] == '9') temph |= 0x09; if (recmess[4] == 'a') temph |= 0x0a; if (recmess[4] == 'b') temph |= 0x0b; if (recmess[4] == 'c') temph |= 0x0c; if (recmess[4] == 'd') temph |= 0x0d; if (recmess[4] == 'e') temph |= 0x0e; if (recmess[4] == 'f') temph |= 0x0f; } // // main subroutine // main() {

Page 8: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

init(); // initialize controller initpwm(); // initialize PWM tempcount = 0; // zero counter rc = &recmess[0]; // initialize char array // // // Main Loop // // while (1) { if (strdone) // if a string has been received { if (recmess[0] == 'p') // if 1st is p do pwm adjust if (recmess[1] == 'o') // if 2nd is o means output { if (recmess[2] == '1') // if 3rd is 1 adjust pwm 1 { stoh(); // convert 4th and 5th chars

// to hex CCPR1L = temph; // send hex out as

//duty cycle } if (recmess[2] == '2') // adjust pwm 2 { stoh(); CCPR2L = temph; } }

if (recmess[0] == 'a' // if 1st is a then read //analog voltage

if (recmess[1] == 'i') // if 2nd is i then input { if (recmess[2] == 'a') // if 3rd is a then read

// from port a { if (recmess[3] == '0') // if 4th is 0 read an0 { ADCON0 = 0x81; // set

// amux to an0 a2dset(); // get a2d

// sample

Page 9: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

} if (recmess[3] == '1') // if 4th is 1 read an1 { ADCON0 = 0x89; a2dset(); } if (recmess[3] == '2') // if 4th is 2 read an2 { ADCON0 = 0x91; a2dset(); } if (recmess[3] == '3') { ADCON0 = 0x99; a2dset(); } if (recmess[3] == '5') { ADCON0 = 0xa1; a2dset(); } } if (recmess[2] == 'e') // if 3rd is e then read

// from port e { if (recmess[3] == '0') { ADCON0 = 0xa9; a2dset(); } if (recmess[3] == '1') { ADCON0 = 0xb1; a2dset(); } if (recmess[3] == '2') { ADCON0 = 0xb9; a2dset();

Page 10: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

} } } if (recmess[0] == 't') // if the test string is

// sent if (recmess[1] == 'e') // respond with

// sending hello if (recmess[2] == 's') if (recmess[3] == 't') { recmess[0] = 'h'; recmess[1] = 'e'; recmess[2] = 'l'; recmess[3] = 'l'; recmess[4] = 'o'; recmess[5] = '$'; sendstring(rc); } if (recmess[0] == 'd') // if 1st is d then

// digital if (recmess[1] == 'i') // if 2nd is i then input if (recmess[2] == 'b') // if 3rd is b then read

// digital port b { TRISB = 0xff; tempcount = PORTB; convcount(); // convert binary to

// string sendstring(rc); // send string } if (recmess[0] == 'd') // if 1st is d then

// digital if (recmess[1] == 'o') // if 2nd is o then

// output if (recmess[2] == 'd') // if 3rd is d then write

// digital to port d { TRISD = 0; stoh(); // convert string to

// hex PORTD = temph; // set port d to digital

// value }

Page 11: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

strdone = 0; // reset strdone flag tempcount = 0; // reset tempcount RCIF = 0; // reset interrrput flag rc = &recmess[0]; // reset string pointer } } } The code is pretty raw and could use a little bit of massaging to make it, however, it all works and I am leaving it as such. On the PC side I used Visual C# and its serial port component to provide the communication interface. So I start with a blank project and drag the serialport component onto the page, name it sp and configure it to match the Pic’s communication settings. Next, I drew sliders, buttons, and textboxes as you can see below.

Page 12: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

The main hitch with using the serialport component is that it is a multithread component. Hence, in order for you to receive data you must write an event handler. So for your DataReceived event you must put this this.Invoke(new EventHandler(DoUpdate)); This will retrieve the data from the other thread and update the field on your windows form. This turned out to be a simple fix. Other than that the rest of the windows code is below, again not pretty but it does work. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace serial { public partial class Form1 : Form { Encoding ascii = Encoding.ASCII; byte[] barray = new byte[6]; char[] carray = new char[6]; char[] darray = new char[6]; char[] sm; public Form1() { InitializeComponent(); } private void sendbut_Click(object sender, EventArgs e) { char[] sm; if (sendtext.Text != "") { sm = sendtext.Text.ToCharArray(); sp.Write(sm, 0, sm.Length); } else MessageBox.Show("No Text Present");

Page 13: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

} private void sp_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { this.Invoke(new EventHandler(DoUpdate)); } private void DoUpdate(object s, EventArgs e) { int i; byte b; i = 0; recvdtext.Text = ""; while (sp.BytesToRead != 0) { b = (byte) sp.ReadByte(); barray[i] = b; i++; } ascii.GetChars(barray, 0, 6, carray, 0); s = new string(carray); s = ""; ascii.GetChars(barray, 0, i, darray, 0); s = new string(darray); i = s.ToString().IndexOf("$", 0); s = s.ToString().Substring(0, i); if (sendtext.Text == "aia0$") a2d0text.Text = s.ToString(); if (sendtext.Text == "aia1$") a2d1text.Text = s.ToString(); if (sendtext.Text == "aia2$") a2d2text.Text = s.ToString(); if (sendtext.Text == "aia3$") a2d3text.Text = s.ToString(); if (sendtext.Text == "aia5$") a2d4text.Text = s.ToString(); if (sendtext.Text == "aie0$") a2d5text.Text = s.ToString(); if (sendtext.Text == "aie1$") a2d6text.Text = s.ToString(); if (sendtext.Text == "aie2$") a2d7text.Text = s.ToString(); if (sendtext.Text == "dib$") pbtext.Text = s.ToString(); recvdtext.Text = s.ToString();

Page 14: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

} private void Form1_Load(object sender, EventArgs e) { sp.Open(); } private void pwmslider_ValueChanged(object sender, EventArgs e) { int tempcount; char[] sm; sendtext.Text = "po1"; tempcount = pwmslider.Value; if (pwmslider.Value > 239) { sendtext.Text += 'f'; tempcount -= 240; goto lsd; } if (pwmslider.Value > 223) { sendtext.Text += 'e'; tempcount -= 224; goto lsd; } if (pwmslider.Value > 207) { sendtext.Text += 'd'; tempcount -= 208; goto lsd; } if (pwmslider.Value > 191) { sendtext.Text += 'c'; tempcount -= 192; goto lsd; } if (pwmslider.Value > 175) { sendtext.Text += 'b'; tempcount -= 176; goto lsd;

Page 15: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

} if (pwmslider.Value > 159) { sendtext.Text += 'a'; tempcount -= 160; goto lsd; } if (pwmslider.Value > 143) { sendtext.Text += '9'; tempcount -= 144; goto lsd; } if (pwmslider.Value > 127) { sendtext.Text += '8'; tempcount -= 128; goto lsd; } if (pwmslider.Value > 111) { sendtext.Text += '7'; tempcount -= 112; goto lsd; } if (pwmslider.Value > 95) { sendtext.Text += '6'; tempcount -= 96; goto lsd; } if (pwmslider.Value > 79) { sendtext.Text += '5'; tempcount -= 80; goto lsd; } if (pwmslider.Value > 63) { sendtext.Text += '4'; tempcount -= 64; goto lsd; } if (pwmslider.Value > 47) { sendtext.Text += '3';

Page 16: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

tempcount -= 48; goto lsd; } if (pwmslider.Value > 31) { sendtext.Text += '2'; tempcount -= 32; goto lsd; } if (pwmslider.Value > 15) { sendtext.Text += '1'; tempcount -= 16; goto lsd; } //if (pwmslider.Value < 16) //{ sendtext.Text += '0'; //tempcount -= 16; //goto lsd; //} lsd: if (tempcount == 15) { sendtext.Text += 'f'; goto cnvdone; } if (tempcount == 14) { sendtext.Text += 'e'; goto cnvdone; } if (tempcount == 13) { sendtext.Text += 'd'; goto cnvdone; } if (tempcount == 12) { sendtext.Text += 'c'; goto cnvdone; } if (tempcount == 11) { sendtext.Text += 'b';

Page 17: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

goto cnvdone; } if (tempcount == 10) { sendtext.Text += 'a'; goto cnvdone; } if (tempcount == 9) { sendtext.Text += '9'; goto cnvdone; } if (tempcount == 8) { sendtext.Text += '8'; goto cnvdone; } if (tempcount == 7) { sendtext.Text += '7'; goto cnvdone; } if (tempcount == 6) { sendtext.Text += '6'; goto cnvdone; } if (tempcount == 5) { sendtext.Text += '5'; goto cnvdone; } if (tempcount == 4) { sendtext.Text += '4'; goto cnvdone; } if (tempcount == 3) { sendtext.Text += '3'; goto cnvdone; } if (tempcount == 2) { sendtext.Text += '2';

Page 18: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

goto cnvdone; } if (tempcount == 1) { sendtext.Text += '1'; goto cnvdone; } sendtext.Text += '0'; cnvdone: sendtext.Text += '$'; sm = sendtext.Text.ToCharArray(); sp.Write(sm, 0, 6); } private void pwm2slider_ValueChanged(object sender, EventArgs e) { int tempcount; sendtext.Text = "po2"; tempcount = pwm2slider.Value; if (pwm2slider.Value > 239) { sendtext.Text += 'f'; tempcount -= 240; goto lsd1; } if (pwm2slider.Value > 223) { sendtext.Text += 'e'; tempcount -= 224; goto lsd1; } if (pwm2slider.Value > 207) { sendtext.Text += 'd'; tempcount -= 208; goto lsd1; } if (pwm2slider.Value > 191) { sendtext.Text += 'c';

Page 19: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

tempcount -= 192; goto lsd1; } if (pwm2slider.Value > 175) { sendtext.Text += 'b'; tempcount -= 176; goto lsd1; } if (pwm2slider.Value > 159) { sendtext.Text += 'a'; tempcount -= 160; goto lsd1; } if (pwm2slider.Value > 143) { sendtext.Text += '9'; tempcount -= 144; goto lsd1; } if (pwm2slider.Value > 127) { sendtext.Text += '8'; tempcount -= 128; goto lsd1; } if (pwm2slider.Value > 111) { sendtext.Text += '7'; tempcount -= 112; goto lsd1; } if (pwm2slider.Value > 95) { sendtext.Text += '6'; tempcount -= 96; goto lsd1; } if (pwm2slider.Value > 79) { sendtext.Text += '5'; tempcount -= 80; goto lsd1; } if (pwm2slider.Value > 63)

Page 20: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

{ sendtext.Text += '4'; tempcount -= 64; goto lsd1; } if (pwm2slider.Value > 47) { sendtext.Text += '3'; tempcount -= 48; goto lsd1; } if (pwm2slider.Value > 31) { sendtext.Text += '2'; tempcount -= 32; goto lsd1; } if (pwm2slider.Value > 15) { sendtext.Text += '1'; tempcount -= 16; goto lsd1; } sendtext.Text += '0'; lsd1: if (tempcount == 15) { sendtext.Text += 'f'; goto cnvdone1; } if (tempcount == 14) { sendtext.Text += 'e'; goto cnvdone1; } if (tempcount == 13) { sendtext.Text += 'd'; goto cnvdone1; } if (tempcount == 12) { sendtext.Text += 'c';

Page 21: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

goto cnvdone1; } if (tempcount == 11) { sendtext.Text += 'b'; goto cnvdone1; } if (tempcount == 10) { sendtext.Text += 'a'; goto cnvdone1; } if (tempcount == 9) { sendtext.Text += '9'; goto cnvdone1; } if (tempcount == 8) { sendtext.Text += '8'; goto cnvdone1; } if (tempcount == 7) { sendtext.Text += '7'; goto cnvdone1; } if (tempcount == 6) { sendtext.Text += '6'; goto cnvdone1; } if (tempcount == 5) { sendtext.Text += '5'; goto cnvdone1; } if (tempcount == 4) { sendtext.Text += '4'; goto cnvdone1; } if (tempcount == 3) { sendtext.Text += '3';

Page 22: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

goto cnvdone1; } if (tempcount == 2) { sendtext.Text += '2'; goto cnvdone1; } if (tempcount == 1) { sendtext.Text += '1'; goto cnvdone1; } sendtext.Text += '0'; cnvdone1: sendtext.Text += '$'; sm = sendtext.Text.ToCharArray(); sp.Write(sm, 0, 6); } private void setpd_Click(object sender, EventArgs e) { sendtext.Text = "dod"; sendtext.Text += pdtext.Text; sendtext.Text += "$"; sm = sendtext.Text.ToCharArray(); sp.Write(sm, 0, 6); } private void getad0_Click(object sender, EventArgs e) { sendtext.Text = "aia0$"; sm = sendtext.Text.ToCharArray(); sp.Write(sm, 0, 5); } private void getad1_Click(object sender, EventArgs e) { sendtext.Text = "aia1$"; sm = sendtext.Text.ToCharArray(); sp.Write(sm, 0, 5); } private void getad2_Click(object sender, EventArgs e) {

Page 23: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

sendtext.Text = "aia2$"; sm = sendtext.Text.ToCharArray(); sp.Write(sm, 0, 5); } private void getad3_Click(object sender, EventArgs e) { sendtext.Text = "aia3$"; sm = sendtext.Text.ToCharArray(); sp.Write(sm, 0, 5); } private void gatad4_Click(object sender, EventArgs e) { sendtext.Text = "aia5$"; sm = sendtext.Text.ToCharArray(); sp.Write(sm, 0, 5); } private void getad5_Click(object sender, EventArgs e) { sendtext.Text = "aie0$"; sm = sendtext.Text.ToCharArray(); sp.Write(sm, 0, 5); } private void getad6_Click(object sender, EventArgs e) { sendtext.Text = "aie1$"; sm = sendtext.Text.ToCharArray(); sp.Write(sm, 0, 5); } private void getad7_Click(object sender, EventArgs e) { sendtext.Text = "aie2$"; sm = sendtext.Text.ToCharArray(); sp.Write(sm, 0, 5); } private void getpb_Click(object sender, EventArgs e) { sendtext.Text = "dib$"; sm = sendtext.Text.ToCharArray(); sp.Write(sm, 0, 4); }

Page 24: PC to Pic Microcontroller by Bruce Misnerelectricallabs.lakeheadu.ca/projects/picc16/projects/pc2pic.pdf · PC to Pic Microcontroller by Bruce Misner This project is intended to show

private void testbut_Click(object sender, EventArgs e) { sendtext.Text = "test$"; sm = sendtext.Text.ToCharArray(); sp.Write(sm, 0, 5); } } }