Jump to content

madie

EstablishedMember
  • Content Count

    11
  • Joined

  • Last visited

Community Reputation

0 Neutral

About madie

  • Rank
    Newbrie
  1. i have try this code to receive a character from rs232 comm (max232 connected to RC7 & RX7).... unsigned char d; while (1) { delay_ms(1000); clear_bit(portb,1); delay_ms(1000); set_bit(portb,1); d = recvChar(); if (d =0x70) clear_bit (portb,0); else set_bit (portb,0); } the function recvChar() is... unsigned char recvChar( void ) { rcreg= 0; RECV_ENABLE= 1; while ( DATA_RECV != 0 ); RECV_ENABLE= 0; return( rcreg ); } then i progarammed in PIC..then it seem like PIC stop at set_bit (portb,0); Q1. Why this happened??i'm quite new in C language..anybody cancommnet this? Q2. I try to change if (d =0x70) to if (d ="H") ...then error below will popups. D:\Projek Sarjana Folder\SourceBoostProjek\Serial\receive character.c(194:7): error: can't convert 'unsigned char*' to 'unsigned char' Why? this happend? how use (" ") actually? Q3. then i change code in Q2 to if (d ='H') ..the no error shows.. What diff between (" ") and (' ')? Q4. what is the value "d" after d = recvChar(); is call? when we send "H" from hyperterminal to pic..is it H in ascii? rcreg should be between 0-255...so it is decimal..when put if (d ='H') ,does the if statement will execute? or we should put if(d='decimal number for H') ? i think too many question i ask..like i say..i'm newbie in C...anybody that could explain to me will beappreciated.. thank you in advance..
  2. it is ok if i put this code in while loop? unsigned char ch; ch = recvChar(); if (ch =="H") { portb = 255; } if (ch=="L") { portb = 0; } just a function to read one character H & L to ON and OFF the portb.. i have tried this..but there is noop also on portB
  3. i have no problem when transmitting data from PIC.... i can check whether the data has been transmit or not by PIC.. function below seems working when transmitting data to from PIC.. void sendChar(char value) { while((txsta & 1 << TRMT) == 0); txreg = value; } void sendString(const char* text) { char i = 0; while(text[i] != 0) sendChar(text[i++]); } all in need now is function receive data by PIC and confirmation by ON certain port using LED..
  4. thanks fred..good example..im using your function given and put in my programm...here is the code after modificationson your code i term of "PORTB" to "portb"..then i build it..no errors... #pragma CLOCK_FREQ 3686400 #include <system.h> //////////////////////////////////////////////////////////////////////////// // The following three sections have been copied from the serial_driver.h file // USART software implementation template arguments and variables // USART hardwareware implementation template arguments //////////////////////////////////////////////////////////////////////////// // // **** START OF DEFAULTS USED FOR SOFTWARE USART EMULATION **** // // RAM used by the software USART driver to emulate the equivalent serial hardware registers // Note this section is really just reserving the space. The defines in the subsequent section // overlay these RAM locations unsigned short sw_SPBRG@0x47; // define location for the emulated SSPCON1 unsigned short sw_RCREG@0x48; // define location for the emulated SSPCON2 unsigned short sw_TXREG@0x49; // define location for the emulated SSPSTAT unsigned short sw_TXSTA@0x4A; // define location for the emulated SSPBUF unsigned short sw_RCSTA@0x4B; // define location for the emulated SSPADD unsigned short sw_TXIF_PIR@0x4C;// define location for the emulated TXIF_PIR1 unsigned short sw_RCIF_PIR@0x4C;// define location for the emulated RCIF_PIR1 //////////////////////////////////////////////////////////////////////////// // USART software implementation template argument values //////////////////////////////////////////////////////////////////////////// // variables cannot be passed as template arguments. The following constants map to // the PIC registers and software emulated USART RAM locations. These constants are // then used by the templated functions. When changing the address of an emulated // register the corresponding constant mapping must also be changed. // PIC16F87x defaults for hardware USART support // register explanations added rjg #define TX_PORT 0x07 //port c #define TX_TRIS 0x87 //trisc #define TX_BIT 6 //pin6 port c #define RX_PORT 0x07 //port c #define RX_TRIS 0x87 //trisc #define RX_BIT 7 #define e_SPBRG 0x99 //baudrate generator #define e_RCREG 0x1a //usart receive data register #define e_TXREG 0x019 //usart transmit data register #define e_TXSTA 0x98 //txsta #define e_RCSTA 0x18 //rcsta #define e_TXIF_PIR 0x0c //PIR1 #define e_RCIF_PIR 0x0c //PIR1 #define e_TXIF_BIT 4 #define e_RCIF_BIT 5 #define MODE (USART_reset_wdt | USART_HW) //////////////////////////////////////////////////////////////////////////// // bit_time is used by the software emulated USART and is the number of CPU // instruction cycles per bit. // // bit_time = FOSC / 4 / BAUDRATE // The maximum value of bit_time currently limited to approximately 24000 // and is determined by the maximum word size supported by the compiler. // this will change when 32 bit variables are supported. // At FOSC of 40MHz the minimum standard baud rate is 600 baud. // When using the software emulated USART functions ensure that the baud rate // can be realistically supported by the FOSC used. bit_time values below // 36 will likely lead to unreliable comms. // // The software UART takes 8 instruction cycles in a bit time loop. Therefore // the driver software divides the bit_time value by 8. If experimenting with // different values for bit_time use increments of 8 to guarentee a different // bit time is selected //////////////////////////////////////////////////////////////////////////// //#define bit_time 86 // 115200 baud at 40MHz #define bit_time 96 // 9600 baud at 3.6864MHz //////////////////////////////////////////////////////////////////////////// // Serial Control Flag Bits used for the MODE parameter // // DO NOT REMOVE THE COMMENTS FROM THE FOLLOWING FLAGS // These flags are defined in serial_driver.h and are include here for information // only. These flags are used in the MODE parameter. // // The USART_invert flag is used to signal the software UART that the serial // input and output signals are inverted from normal RS232 communications. // Hardware implementations that use standard RS232 transievers // such as MS1488/MC1489 or MAX232 line drivers / receivers do NOT require this flag. // // The flags USART_HW and the USART_invert are mutually exclusive. // // Sample use: #define MODE (USART_reset_wdt | USART_HW) // //////////////////////////////////////////////////////////////////////////// // define USART Mode bits #define USART_HW 0x01 // specifies use the HW USART in the PIC //#define USART_invert 0x02 // invert the tx and rx bits #define USART_reset_wdt 0x04 // reset the WDT while waiting for a character in getc() #define MODE (USART_reset_wdt | USART_HW) // **** END OF DEFAULTS USED FOR SOFTWARE USART EMULATION **** #include <rs232_driver.h> ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// //////RECEIVE CHARACTER FUNCTION BY FRED////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// volatile bit RECV_ENABLE@RCSTA.CREN; volatile bit DATA_RECV@PIR1.RCIF; unsigned char recvChar( void ) { rcreg= 0; RECV_ENABLE= 1; while ( DATA_RECV != 0 ); RECV_ENABLE= 0; return( rcreg ); } void recvStr( unsigned char *str ) { unsigned char c, i; c= recvChar(); i= 0; while ( (c != 0xd) && ( c!= 0xa )) { // until a return or linefeed is received str[i++]= c; c= recvChar( ); } str[i]= 0x0; return; } unsigned char recv_and_set_pbit(void) { unsigned char str[30], pbit; recvStr( str ); if ( *str ) { pbit= str[3] - '0'; // "M1O2", get the ascii 2 and convert to 0x2 if (( pbit >= 1) && (pbit<= 4)) set_bit( portb, pbit ); } return( pbit ); } //////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// ///////////////////END OF RECEIVE CHARACTER FUNCTION//////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// void main() { // set option register clear_bit(option_reg,T0CS); //Disable all interrupts clear_bit( intcon, GIE ); //disable interrupts //Init ports //A & B port initialization trisb = 0; //All pins configured for output portb = 0; //Turn Port A to Digital Outputs set_bit(adcon1, ADFM); // set_bit(adcon1, PCFG0); // set_bit(adcon1, PCFG1); // set_bit(adcon1, PCFG2); // clear_bit(adcon1, PCFG3); trisa = 0; //All pins configured for output porta = 0; // for the hardware UART the paramter passed is the divisor // the hardware usart enables dynamic reconfiguration of the baud rate // the software emulated USART baud rate is defined by constants in // serial_driver.h - this file alos contains the address mapping for // RAM required to support the software emulated USART uart_init(1,23); // set high speed divisor mode and divisor value (9600 baud rate) while (1) { recv_and_set_pbit(); } } but then I send "M1O2" to RX/RC7 (PIC16F876) using MAX232 driver...there is no output on port b....led connected to port b should be ON..is there something wrong the setup/initializein my code?
  5. tanks..i have change the define bit_time to.. #define bit_time 96 // 9600 baud at 3.6864MHz and it going well..thanks.. the serial communication test program given is only to send a character/string.. how about getting string or character from serial port... i have tried the "getc"..but it won't work.. any suggestion..? i want to implemet serial comm for controlapplication..when PIC received string "M1O1"...then RB1 will be on..."M1O2" then RB2 will be on..and so on.. i send the string from a computer using VB (via mscomm 6.0 VB component).. I have done the VB interface with 4 buttons for RB1,RB2, RB3, RB4.. every time i click a button string "M1oX" will be send.. need some suggestionon how to received the strings and ON regarding PIC I/O pins... Thanks.. ~madie~
  6. for your information, i'm using max232 as interface for serial pin...using 3 wire connection.. i think i can left this code as default.. // Serial Control Flag Bits used for the MODE parameter // // DO NOT REMOVE THE COMMENTS FROM THE FOLLOWING FLAGS // These flags are defined in serial_driver.h and are include here for information // only. These flags are used in the MODE parameter. // // The USART_invert flag is used to signal the software UART that the serial // input and output signals are inverted from normal RS232 communications. // Hardware implementations that use standard RS232 transievers // such as MS1488/MC1489 or MAX232 line drivers / receivers do NOT require this flag. // // The flags USART_HW and the USART_invert are mutually exclusive. // // Sample use: #define MODE (USART_reset_wdt | USART_HW) // //////////////////////////////////////////////////////////////////////////// // define USART Mode bits //#define USART_HW 0x01 // specifies use the HW USART in the PIC //#define USART_invert 0x02 // invert the tx and rx bits //#define USART_reset_wdt 0x04 // reset the WDT while waiting for a character in getc() // **** END OF DEFAULTS USED FOR SOFTWARE USART EMULATION **** then i try to send only the character "H" then i got this "ÊŠ"..
  7. hi ryeq.. i'm trying to do the same as you have done..but i have a problems..the string come out from the serial is not "Hello, world"...i get "·+Ѥ#JѬ˂"....what is my problem? for your information..i dont use hyperterminal because i dont know how to use it..i use my own program using VB with mscomm component...i ave try almst the same code using Rabbit microcontroller, then i dont have any problem to display "Hello world".. can anybody guide me? thanks in advance.. ~Madie~
  8. This is not a bug, on the PIC16F876A RA4 is open drain, that means the pin can only go low. The LEDs in the LED block in the simulation needs the pins to be taken to 5V for the LEDs to illuminate, which can't be done with an open drain output. Regards Dave <{POST_SNAPBACK}> yes...i know RA4 is open drain...ofcourse 5V source is needed for hardware..but it is same for this simulation? i'm just thinking this simulation is configured both (open drain and open source).lol.. anyway..thanks..i solve my pboblem..and my hardware now work fine..
  9. thanks all my friends..yuo help me a lots..i thinks cac001 was correct..there is a bug in the SourceBoost simulator (beetle bugs )..RA4 will never blink using sourceboost simulator...but it will when using real hardware.. thanks averybody..
  10. thanks all my friends.. you have help me a lots. I have done everythig that have been suggested by you..Its seem that cac001 is correct..there is a bug in the SourceBoost simulator....RA4 will never blink till the end..
  11. hi..this is my first post in here..i hope there is somebody will help me.. i have create a program to blink led all port in PIC16F876...i get this code from winpic website and try to test using soureboost with led plugin.. then i'm stuck here when all port seems ok except for port A.. RA4,RA6 & RA7 is not produce any output.. i have questions. 1. what is means by #pragma DATA 0x2007, 0x3FF9 // XT,!CP,!WDT,!PWRT,BODEN,LPV,!CPD,WRT,!DEBUGGER 2.does this line of code affect the PORT A as ADC? 3.initially all pins in port A did not produce any output,then when I put adcon1 RA0,RA1,RA2,RA3&RA5 produce output..is there need to configure adon1? for your ref, here is my code.. /* 6/24/03 Copyright Spark Fun Electronics 2003© Classic Blinking Test Routine for the 40 Pin PIC16F876 Flashes all pins on PIC - 3.6864MHz operations */ #include <system.h> #ifdef _BOOSTC //Define device config block #pragma DATA 0x2007, 0x3FF9 // XT,!CP,!WDT,!PWRT,BODEN,LPV,!CPD,WRT,!DEBUGGER #else //Define device config block asm { list p=PIC16F876 __config H'3FF9' ;XT,!CP,!WDT,!PWRT,BODEN,LPV,!CPD,WRT,!DEBUGGER } #endif ////////////////////////////////////////////// // Main program entry ////////////////////////////////////////////// void main() { //Disable all interrupts clear_bit( intcon, GIE ); //disable interrupts //Init ports //A, B, C, D and E port initialization trisb = 0; //All pins configured for output trisc = 0; //All pins configured for input portb = 0; portc = 0; //Turn Port A to Digital Outputs set_bit(adcon1, ADFM); // clear_bit(adcon1, PCFG0); // set_bit(adcon1, PCFG1); // set_bit(adcon1, PCFG2); // clear_bit(adcon1, PCFG3); trisa = 0; //All pins configured for output porta = 0; while(1) { porta = 255; portb = 255; portc = 255; delay_ms(100); porta = 0; portb = 0; portc = 0; delay_ms(100);}} //General short delay void delay_ms(unsigned char t); thanks, Regards.. madie (M'sia)
×
×
  • Create New...