Archives
-
Visual Basic 6.0 serial communication with PIC 16F877A
Hi all,
I am working on the micro controller programming part of the following VB app. http://www.rentron.com/sending_data.htm
I am using CCS info and my MCU is PIC 16F877A. I am stuck at how to retrieve back the characters sent from VB, I need to separate them and apply them accordingly.
VB sends the pin number and its state, I need to turn ON the corresponding LED.
VB code:
Code:
‘ Send Out Data
MSComm1.Output = Chr$(PinNumber) amp Chr$(PinState)This is the MCU code I have come up with. But I don’t know how to retrieve the Pin number and pinstate, kindly guide me.
Code:
#include “D:\Documents\Talha’s documents\FAST\FYP\codes_CCS\SerialCom-VB\scomvb.h”void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);char cmd;
do{
if(kbhit())
{output_b(0×00);
cmd=getch();switch (cmd)
{
case 0:output_bit(PIN_B0,1 );
break;
case 1:output_bit(PIN_B1,1 );
break;
case 2:output_bit(PIN_B2,1 );
break;
case 3:output_bit(PIN_B3,1 );
break;
case 4:output_bit(PIN_B4,1 );
break;
case 5:output_bit(PIN_B5,1 );
break;
case 6:output_bit(PIN_B6,1 );
break;
case 7:output_bit(PIN_B7,1 );
break;
}
}
}while(1);
}
Please refer to above URL for full VB part.Related Forum Messages
- Integer input
- 6 led control problem
- About output_bit() & output_x() discussion
- How to start with spi communication?
- What’s wrong with this chunk of code for pic16f876a
- DC motors with L293D not running..
- 4094 ShiftRegister 3 wire LCD – Driver By (Fattah-Tafreshi)
- IRP Bit must be set manually for indirect access to ?lstr_fi
- Sleep is taking imprecise life time.
- Switch instruction in mikroC PRO for PIC?!
- Rs232 character receiving
- Switch Case question
- Duplicate Case error for switch command
- [SOLVED] problem with the following MikroC code
- ??N 1210 + PIC18F4550
- Best way to convert byte to String?
- String with case function
- Weird things happening with LED matrix
- Key Pad routines
- How to read input from keypad twice or more than once?
I am trying to write a rountine for pic18f4523 in C using ccs-picc. i couldnt find anything like getch() for capturing a integer input via RS 232 ?? Does anyone have a hint how i can achieve it like refer to the following piece of code : #include lt18F4523.hgt #include ltstdio.hgt #use delay(internal=8M)// internal oscillator 8Mhz #fuses NOWDT #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,st ream=,bits=8) // using internal oscillator with CKO at RA6 int menu(void); void main() { while(1) { switch (menu()) { case 1: { output_bit(PIN_A0,1); delay_ms(1000); output_bit(PIN_A0,0); break; } case 2: { output_bit(PIN_A1,1); delay_ms(1000); output_bit(PIN_A1,0); break; } case 3: { output_bit(PIN_A2,1); delay_ms(1000); output_bit(PIN_A2,0); break; } default: { output_bit(PIN_A0,0); output_bit(PIN_A1,0); output_bit(PIN_A2,0); break; } } } ///////User Selection Menu////////////////////////////// int menu(unsigned int) { unsigned int ch; printf ("\n\r Press A to turn LED on RA0 ......."); printf ("\n\r Press B to turn LED ...i wanna control 6 led with 6 button but when i run the program in simulation, it didn't work.Where is my fault?i wait your helps Quote: #use delay(4000000) #use fast_io(a) #use fast_io(b) int1 x,y,z,a,b,c ; void main() { setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); set_tris_a(0b00011111); set_tris_b(0b00000001); while(1) x=input(pin_a0); output_bit(pin_b0,x); y=input(pin_a1); output_bit(pin_b1,y); z=input(pin_a2); output_bit(pin_b2,z); a=input(pin_a3); output_bit(pin_b3,a); b=input(pin_a4); output_bit(pin_b4,b); c=input(pin_b0); output_bit(pin_b0,c); }Hello guys, I have a question with PIC16f877a. When I program the C code as follows: Code: #include "D:\PICprogram\12864LCD_20100901.h" #include lt16f877a.hgt #fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD,NOWRT #use delay(CLOCK=20000000) #use fast_io(B) void init_lcd() { set_tris_b(0x00); output_b(0x0f); } void main() { init_lcd(); while(1); } My DEMO board PINS are defined as follows: LED0_RB0-----PIN_B0 LED1_RB1-----PIN_B1 LED2_RB2-----PIN_B2 LED3_RB3-----PIN_B3 The LED1 amp LED2 light, the other is not light, ...I am beginner to spi communication. 1. I don't know where I made mistake in the following program. (I have tried to send a bit from master to slave and display through slave). 2. I don't know how to connect wires in hardware part and what are all required. Whether we have to write code for clock pulse generation or PIC do it on own? plz explain from ABC.... Provide example code for the following cases if possible. 1. Master sends data. Slave receives and displays. 2. Master sends data. Slave re-send some data and master displays. ...this section of code has been written for getting data from tristate buffer IC using multiplexing technique but it's not working. compiler being used is HITECH C whereas I wrote same section of code using CCS C compiler and it works fine. In that version I used its library functions. I am putting here both the versions. Please suggest what wrong I am doing with HITECH C version of code. Thanks Code : HITECH C version unsigned char getdata(unsigned char address) { unsigned char x; switch(address) { case 0x1: RA0 = 0; TRISA0 = 0; TRISB = 0xff; x = PORTB; RA0 ...Hi all, what could make this code from not running properly?? H bridge: L293D 2 DC motors connected to each side of L293D. It waits for corresponding character from VB app before taking the action. Code: #include "C:\Documents and Settings\Talha\My Documents\codes_CCS\VB_DC motor all directions\vb_motor_all directns.h" #define LEFT_CONTROL_2A PIN_C0 //2A of L293D #define LEFT_CONTROL_1A PIN_C1 //1A #define LEFT_MOTOR PIN_C2 //1,2EN #define LED PIN_D1 #define RIGHT_MOTOR PIN_D4 //3,4EN #define RIGHT_CONTROL_4A PIN_D5 //4A #define RIGHT_CONTROL_3A PIN_D6 //3A void backward() { ...Code: //main.c //Fattah-Tafreshi //fattah.roland@gmail.com //2011 //4094 LCD Serial #include "main.h" //4094 PINs #define data PIN_B0 #define clock PIN_B1 #define Strobe PIN_B2 #include "f_lcd.c" void main() { int i; setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); lcd_init(); for(i=0;ilt=15;i++) { lcd_gotoxy(i,1); lcd_putc('-'); lcd_gotoxy(16-i,2); lcd_putc('-'); ...I try to do this programming below, void Command_AT(char *AT){ } void main(void){ while(1){ ...... ...... ..... switch (m) { case 1 :Command_AT("01041") ; break; case 2 :Command_AT("01051") ; break; case 3 :Command_AT("010A1") ; break; case 4 :Command_AT("010B1") ; break; case 5 :Command_AT("010C2") ; break; case 6 :Command_AT("010D1") ; break; case 7 :Command_AT("010E1") ; break; case 8 :Command_AT("010F1") ; break; case 9 :Command_AT("01102") ; break; case 10 :Command_AT("01111") ; break; case 11 :Command_AT("011F2") ; break; case 12 :Command_AT("01232") ; break; case 13 :Command_AT("012C1") ; break; case 14 :Command_AT("012E1") ; break; case 15 :Command_AT("012F1") ; break; case 16 :Command_AT("01331") ; break; ...Hello, I'm trying to build a project using Pic16f688 that sleep for an 1 hour wake up using the WDT do some stuff and go back to sleep again repeating this same process endlessly. I know that the WDT can only reset it self in a maximum 268s, so I'm going have to count until it lasts for one hour, but it seems that the time of sleep is imprecise, I used the code below just to verify if the WDT is waking up and its taking around 5 min and 20 sec. Code: #include "16F688.h" #include "Timer.h" #fuses HS, ...Hello.I wrote a program consist of few functions.And in each functions I used switch instructions and at each case of the switch instruction I called functions.But it gives me some errors like of;[719 324 Undeclared identifier 'F1',' F2' ,...,'F17' in expression TST18F8722BX1.c]. Would you please tell me what is wrong with my program? Thanks, **My program; F1(){ .... }//~ ..... F15(){ .... }//~ void main() { ...... }//~! F10(){ //F1 or F2 or...or F15 .... sbtlen0: if ((cursy==7){ switch(cursx){ case 5: F1();break; case 7: F2();break; case 9: F3();break; case 11: F4();break; case 0 : F5();break; case 3 : F6();break; } } sbtlen1: if ((cursy==6){ switch(cursx){ case 1: F7(); break; case 2: F8(); break; case 3: F9(); break; case 4: F10(); break; case 5: F11(); break; case 6: F12(); break; case 7: F13(); break; case ...hello every one i have no much experience with pic i try to send character (or int) with rs232 to break a while loop , the code is ok except the second while loop that i cant escape #include lt16F84.Hgt #use delay(clock=4000000) #use rs232(baud=9600, xmit=PIN_a0, rcv=PIN_a1) void main() { while(1){ char c; c=getc(); switch (c) { case '1': output_high(pin_b0); break; case '4': output_low(pin_b0); break; case '2': output_high(pin_b1); break; case '5': output_low(pin_b1); break; case '3': output_high(pin_b2); break; case '6': output_low(pin_b2); break; case '7': while(!c == '4') {output_high(pin_b0); delay_ms(100); output_low(pin_b0); delay_ms(100);} break; } }All of the examples I see for Switch Case show one integer value for each case. Is it possible to put a range of integer values such as: Code: switch(ADCvalue){ case 0 to 14: beta = 5191; break; case 15 to 39: beta = 5085; break; case 40 to 158: beta = 4942; break; case 159 to 530: beta = 4767; break; case 531 to 577: beta = 4671; break; case 578 to 670: beta = 4641; break; case 671 to 757: beta = 4604; break; case 758 to 832: beta = 4566; break; case 833 to 892: beta = 4526; ...Hi I am trying to parse some incoming data with a switch case command with the following code: Code: void parseReceivedText() { switch (textBuff[8]) { case 'printf_ip' : IPPrint(); break; case 'poe_resta' : PoeRestart(); break; case 'cha_dname' : ChangeDeviceName(); ...- - - Updated - - - Code: void main() { int A = 0; TRISA = 0; TRISB = 0xff; PORTA = 0; PORTB.RB4 = 0; PORTB.RB5 = 0; PORTB.RB6 = 0; PORTB.RB7 = 0; while(1) { A = PORTB; switch(A) { ...I have a magnetometer ??N 1210 linked in SPI to a pic18F4550(master). Datasheet is here: http://www.xensor.nl/pdffiles/sheets/xen1210.pdf Source Code: Code: #include lt18F4550.hgt #device ADC=10 #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN #use delay(clock=48000000) #use spi(MODE=1) #define USB_HID_DEVICE TRUE #define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT #define USB_EP1_TX_SIZE 64 #define USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT #define USB_EP1_RX_SIZE 64 #include ltpic18_usb.hgt #include ltdesc.hgt #include ltusb.cgt void Init_XEN (void) { // POWER-OFF COMMAND output_bit(PIN_B5,1); // CS delay_us(50); ...I spent too much time the other day trying to convert a number held as a byte to characters in a String. The result was code like below. This is not compact nor elegant ad I'd really like to know how it should be done. (RTCmonth is shown fixed here for simplicity, but it's variable in the code. A .CSV file is created with a timestamp as filename) Quote byte RTCmonth = 12; String logfilename = "00000000.csv"; // MMDDHHmm.csv void setlogfilename() { switch (RTCmonth/10) { case 1: logfilename.setCharAt(0,'1'); break; case 2: logfilename.setCharAt(0,'2'); break; ...Hi Is it possible to use a string with case function? I have this example: Code: #int_rda void rda_isr(void) { char c[10]; //c=getc(); c=fgetc(); switch(c) { case '1': output_high(PIN_B7); break; case '2': output_high(PIN_B6); break; ...So im programming a Rainbowduino with an RGB LED matrix on it, and i wrote a program that scrolls a char array accross. Like a any generic LED board does. all the variable letters look kinda like char* a[8]={ "00111100", "01111110", "01100110", "01100110", "01111110", "01111110", "01100110", "01100110"}; And add(char* in[8]) just keeps adding on the lines to 8 strings I have set up(one for each line, named line0,line1...). Here is the important stuff: Code: char output[]="abcdefghijklmnop"; //in setup, adds each letter to the end of each line for(count=0;countltsizeof(output)-1;count++){ switch(output[count]){ case 'a':add(a);break; case 'b':add(b);break; case 'c':add(c);break; case 'd':add(d);break; ...Hi I am trying understand the timelock project and have a few question regarding reading of the keypad. In this project the following code is used: Code: Select all void ReadKeypad(){ // read keypad kp = Keypad_Key_Click(); // Store key code in kp variable if (kp){ switch (kp){ // map the keys case 1: kp = 1;break; // 1 case 2: kp = 2;break; // 2 ...Hello. Most of the examples I see are just reading the keypad once (a single digit). But how do we read the input twice, or more than a single digit? Or more precisely, how do we display the input? For instance, when I press 123, I want to display 123 on the LCD, rather than replacing it? Oh, I purposely put the code as a function in my library. Code: Select all void keypad() { if (printkeypad == 1) { kp = 0; do kp = Keypad_Key_Press(); while (!kp); switch (kp) { case 1: kp = 49; break; case 2: kp = 50; break; case 3: kp = 51; break; case 5: kp = 52; break; case 6: kp ...
