Jump to content

ra68gi

EstablishedMember
  • Content Count

    229
  • Joined

  • Last visited

Everything posted by ra68gi

  1. Hi jwilson, I can see that all the characters from the weight indicator is not printed on the hyperterminal. smiley is some special character( >127 <= 255). why is the load digits not printed. try to get some information regarding serial comm of the indicator. Like say if its got modbus protocol. does it have parity etc. I have worked with similar project. In fact I have constructed a load indicator which sends out 6 digits using TI's adc chip & PIC16F876. Apart from load it also outs encoder value(for displacement). For all my testing I use hyperteminal with no problems. I also have constucted a serial display pcb which receives the serial data & displays. The serial display also has keys to calibrate. Regards Raghunathan.
  2. Hey Guys, I was working on A ps2 keyboard emulator project. A very unique communication protocol. Its similar to RS232 with 8 data bits, 1 odd parity, 1 start & 1 stop bit. It also has clock. Both the clock pin & data pins of the Keyboard is open-collector. So I used the weak pullups of the portb pins for this application. All these days I was of the impression that the PS2 of the key board outs the ascii value of the key character. Only after browsing the net I realised that its got a different set of make code. I needed to verify if my code generated a glitch free wave form & the only way I could do is use the LED block. But that was not of much use. Further more the portb value in the SFR in the simulator shows all ones(binary) even on execution of instruction portb = 0 ; when trisb = 255; Finally I burnt the chip & saw the wave form on the scope. I got the PIC to print a character on any word processor. Thanks, Raghunathan.
  3. Hey guys, I suppose the LED block in the simulator indicates the status of the i/o pin. With PIC16F72 & weak pull-ups enabled(option_reg.7 = 0) & with trisb still in 255, the LEDs in the port is in the OFF state, where as its got to be ON. This happens right at the intialization itself not after any read modify write operation. ie. as soon as instruction option_reg.7 = 0; gets executed. but if this instruction is commented out, then the LEDs are in ON state. Any reason why ? with NO pullups the input pins would be floating. There could be any charge or voltage between vss to vdd( i would best expect the simulator to show a OFF led at this state.) Regards Raghunathan.
  4. Hi Alex, U are right. I did'nt realize that synchronous USART did not have start bit & stop bit and went on to program & test my code. Well, I need to employ some other technique. Actually the ps2 keyboard format is 11 bit data length. I suppose the start bit can be of the same length as rest of the data bits. Let me try using the pwm pin for the clock and load the data bits in tmr2 - pr2 match interrupt(ISR). The data gets validated on the low of the clock pulse. thanks, Raghunathan.
  5. No the driver uses or emulates an asynchronous UART Hi asmallri, I was writing a code to emulate a PS2 key-board, so that data can be printed on any word processor. The keyboard uses 8 data bit, odd parity(9th bit) in rs232 data format with a sych clock(synchronous mode). They say the baud rate is some where near 20kHz to 30kHz. Regards Raghunathan.
  6. Thanks very much Pavel. One more help required. Can u give the code for div64. with that I should manage to complete most projects. Regards Raghunathan.
  7. Hi, I am having situations in which I need to multiply two longs resulting in a data larger then 32bits. Is is possible to include a 64bit data type in boostc ? Regards Raghunathan.
  8. Hi, I want to know if the rs232_driver.h of souce boost be configured for 9bit synchronous mode? Regards Raghunathan
  9. Thanks, I got it to work. These were my findings while testing.. 1) When I plugged my device to different usb port on the laptop the device goes thro' the detection process again and a new com port no. is assigned. 2) Many times I am unable to access the com port with "unable to open com port" message displayed by windows. Can it be made more reliable so that we can use it for real time Industrial projects? I use serial port extensively for may of my industrial projects. When I need to access data from different systems I am forced to use the PCI serial port addon card or the usb to serial converter(similar to picpack emulator). Unable to open com port is one the most common problems I endup with. So I have decided to use a multiplexer like DG201 to communicate using single com port provided in the PC. I want to know if the same cdc driver, contol transfer function can be used for making devices like the usb key pad or a bar code reader, where the data is printed where ever the cursor is present. ie be it word or excel or note pad, it should just print where ever the cursor is present. Regards Raghunathan.
  10. Hi, I am using the usb_serial program from IAN's pic_pack demo example. I have built this program for PIC18F2550, downloaded the hex file into the chip, wired the chip in bus powered mode as shown in the schematic. Upon plugging into the system nothing comes up. I checked for the bus voltage & I got 5v with the right polarity. but when I checked the Vusb pin(pin15), I did not get any voltage. I suppose it should show around 3.3v. what could be wrong? Regards Raghunathan USB_SCHEMATIC_FOR_18F2550.zip
  11. Also called Data Acquisition time. Regards Raghunathan
  12. Thanks Tim for those tips. I will spend some more time going thro' the lib files try to understand the program & then burn the chip. I should be in a position to modify the code to suit my application. will get back to you when I face problems. Regards Raghunathan
  13. I would suggest connecting the hyperterminal to PIC16F690 to verify if it gets the right value & sends the right value. Regards Raghunathan
  14. I think your right. I have this from the version updates.. SourceBoost V6.92 (13-February-2009) BoostC/BoostC++/BoostBasic 1.Fixed LFSR instruction use in inline assembler. 2.Fixed bug when compiler generated incorrect code for expressions like (&First->a)->local_1 = 0x5555; 3.Obj files are now created in the same directory where source files are. Before this change obj files were created in the current directory. I try downloading the latest version. Thanks Raghunathan.
  15. I didn't tamper with the folder at all. I just down loaded the zip file today extracted all the files. opened Sourceboost Ide selected the project & hit build button. Anything to do with the linker options Regards Raghunathan.
  16. I did just that & this is what I got. Building... BoostC Optimizing C Compiler Version 6.92 (for PIC18 architecture) http://www.sourceboost.com Copyright(C) 2004-2009 Pavel Baranov Copyright(C) 2004-2009 David Hobday Licensed to RAGHUNATHAN PARAMASIVAM under Single user Pro License for 1 node(s) Limitations: PIC18 max code size:Unlimited, max RAM banks:Unlimited ..\..\pic_pack_lib\pic_utils.c success BoostC Optimizing C Compiler Version 6.92 (for PIC18 architecture) http://www.sourceboost.com Copyright(C) 2004-2009 Pavel Baranov Copyright(C) 2004-2009 David Hobday Licensed to RAGHUNATHAN PARAMASIVAM under Single user Pro License for 1 node(s) Limitations: PIC18 max code size:Unlimited, max RAM banks:Unlimited ..\..\pic_pack_lib\pic_tick.c success BoostC Optimizing C Compiler Version 6.92 (for PIC18 architecture) http://www.sourceboost.com Copyright(C) 2004-2009 Pavel Baranov Copyright(C) 2004-2009 David Hobday Licensed to RAGHUNATHAN PARAMASIVAM under Single user Pro License for 1 node(s) Limitations: PIC18 max code size:Unlimited, max RAM banks:Unlimited ..\..\pic_pack_lib\pic_timer.c success BoostC Optimizing C Compiler Version 6.92 (for PIC18 architecture) http://www.sourceboost.com Copyright(C) 2004-2009 Pavel Baranov Copyright(C) 2004-2009 David Hobday Licensed to RAGHUNATHAN PARAMASIVAM under Single user Pro License for 1 node(s) Limitations: PIC18 max code size:Unlimited, max RAM banks:Unlimited usb_serial.c C:\Program Files\SourceBoost\Samples\C\BoostC\pic_pack\picpack_2.0\demos\usb_serial\usb_serial.c(133): warning: conversion from 'unsigned int' to 'unsigned char', possible loss of data C:\Program Files\SourceBoost\Samples\C\BoostC\pic_pack\picpack_2.0\demos\usb_serial\usb_serial.c(239:2): warning: expression is always true success BoostC Optimizing C Compiler Version 6.92 (for PIC18 architecture) http://www.sourceboost.com Copyright(C) 2004-2009 Pavel Baranov Copyright(C) 2004-2009 David Hobday Licensed to RAGHUNATHAN PARAMASIVAM under Single user Pro License for 1 node(s) Limitations: PIC18 max code size:Unlimited, max RAM banks:Unlimited usb_config_serial.c success BoostC Optimizing C Compiler Version 6.92 (for PIC18 architecture) http://www.sourceboost.com Copyright(C) 2004-2009 Pavel Baranov Copyright(C) 2004-2009 David Hobday Licensed to RAGHUNATHAN PARAMASIVAM under Single user Pro License for 1 node(s) Limitations: PIC18 max code size:Unlimited, max RAM banks:Unlimited ..\..\pic_pack_lib\usb_cdc_class.c C:\Program Files\SourceBoost\Samples\C\BoostC\pic_pack\picpack_2.0\pic_pack_lib\usb_cdc_class.c(125): warning: conversion from 'unsigned int' to 'unsigned char', possible loss of data success BoostC Optimizing C Compiler Version 6.92 (for PIC18 architecture) http://www.sourceboost.com Copyright(C) 2004-2009 Pavel Baranov Copyright(C) 2004-2009 David Hobday Licensed to RAGHUNATHAN PARAMASIVAM under Single user Pro License for 1 node(s) Limitations: PIC18 max code size:Unlimited, max RAM banks:Unlimited ..\..\pic_pack_lib\pic_usb_buffer_mgt.c success BoostC Optimizing C Compiler Version 6.92 (for PIC18 architecture) http://www.sourceboost.com Copyright(C) 2004-2009 Pavel Baranov Copyright(C) 2004-2009 David Hobday Licensed to RAGHUNATHAN PARAMASIVAM under Single user Pro License for 1 node(s) Limitations: PIC18 max code size:Unlimited, max RAM banks:Unlimited ..\..\pic_pack_lib\pic_usb.c C:\Program Files\SourceBoost\Samples\C\BoostC\pic_pack\picpack_2.0\pic_pack_lib\pic_usb.c(354): warning: assignment of constant to pointer C:\Program Files\SourceBoost\Samples\C\BoostC\pic_pack\picpack_2.0\pic_pack_lib\pic_usb.c(635): warning: conversion from 'unsigned int' to 'unsigned char', possible loss of data success BoostC Optimizing C Compiler Version 6.92 (for PIC18 architecture) http://www.sourceboost.com Copyright(C) 2004-2009 Pavel Baranov Copyright(C) 2004-2009 David Hobday Licensed to RAGHUNATHAN PARAMASIVAM under Single user Pro License for 1 node(s) Limitations: PIC18 max code size:Unlimited, max RAM banks:Unlimited ..\..\pic_pack_lib\pic_serial.c success BoostLink Optimizing Linker Version 6.92 http://www.sourceboost.com Copyright(C) 2004-2009 Pavel Baranov Copyright(C) 2004-2009 David Hobday failure Error: Failed to open:pic_utils.obj Error: Failed to open:pic_tick.obj Error: Failed to open:pic_timer.obj Error: Failed to open:usb_cdc_class.obj Error: Failed to open:pic_usb_buffer_mgt.obj Error: Failed to open:pic_usb.obj Error: Failed to open:pic_serial.obj "C:\Program Files\SourceBoost\boostc.pic18.exe" ..\..\pic_pack_lib\pic_utils.c -t PIC18F4550 -W2 -I "..\..\pic_pack_lib" "C:\Program Files\SourceBoost\boostc.pic18.exe" ..\..\pic_pack_lib\pic_tick.c -t PIC18F4550 -W2 -I "..\..\pic_pack_lib" "C:\Program Files\SourceBoost\boostc.pic18.exe" ..\..\pic_pack_lib\pic_timer.c -t PIC18F4550 -W2 -I "..\..\pic_pack_lib" "C:\Program Files\SourceBoost\boostc.pic18.exe" usb_serial.c -t PIC18F4550 -W2 -I "..\..\pic_pack_lib" "C:\Program Files\SourceBoost\boostc.pic18.exe" usb_config_serial.c -t PIC18F4550 -W2 -I "..\..\pic_pack_lib" "C:\Program Files\SourceBoost\boostc.pic18.exe" ..\..\pic_pack_lib\usb_cdc_class.c -t PIC18F4550 -W2 -I "..\..\pic_pack_lib" "C:\Program Files\SourceBoost\boostc.pic18.exe" ..\..\pic_pack_lib\pic_usb_buffer_mgt.c -t PIC18F4550 -W2 -I "..\..\pic_pack_lib" "C:\Program Files\SourceBoost\boostc.pic18.exe" ..\..\pic_pack_lib\pic_usb.c -t PIC18F4550 -W2 -I "..\..\pic_pack_lib" "C:\Program Files\SourceBoost\boostc.pic18.exe" ..\..\pic_pack_lib\pic_serial.c -t PIC18F4550 -W2 -I "..\..\pic_pack_lib" "C:\Program Files\SourceBoost\boostlink.pic.exe" /ld "C:\Program Files\SourceBoost\lib" libc.pic18.lib pic_utils.obj pic_tick.obj pic_timer.obj usb_serial.obj usb_config_serial.obj usb_cdc_class.obj pic_usb_buffer_mgt.obj pic_usb.obj pic_serial.obj /t PIC18F4550 /d "C:\Program Files\SourceBoost\Samples\C\BoostC\pic_pack\picpack_2.0\demos\usb_serial" /p usb_serial Exit code was -2. Removing target: usb_serial.hex Failed to locate output file 'C:\Program Files\SourceBoost\Samples\C\BoostC\pic_pack\picpack_2.0\demos\usb_serial\usb_serial.hex' Done Failed In the compiler options in the exta compiler I can see this... "-I "..\..\pic_pack_lib"" The linker option is empty. Anything to with it Regards Raghunathan
  17. In fact I even have a printout of the project. I tried building the same project ie. usb_serial and the compiler returned a fail. it says it couldn't find some of the .obj files. can any one say how to build this project(usb_serial) in the demos folder of pic_pack step by step like you would to a child? I confess Iam quite dumb. I want to know which are the files that need to be added to project etc.. The easiest thing would be to just burn the .hex file(only onto pic18f4550) & test it... and I only have a 2550 chip with me right now. Regards Raghunathan.
  18. Hi Reynard, The usb_serial folder also has two other .hex files in the name of usb_serial_works & user_serial. Do u have any idea as why these .hex are in this project file. Regards Raghunathan
  19. Hi guys, I wish to use PIC18F2550 for my usb-uart project. Since Source boost does not have its own library, I have to use the pic_pack lib provided by Ian Harris. I have lots of doubt, but let me start one by one. In his program usb_serial.c, they have used the following header files ie. .h files // Pic Pack includes #include "config.h" #include "pic_utils.h" #include "pic_usb.h" #include "pic_tick.h" #include "pic_timer.h" #include "usb_cdc_class.h" // System includes #include "string.h" #include "stdlib.h" #include "config.h" // If you'd like USB debug info out the serial connection, uncomment this line: //#define USB_SERIAL_DEBUG // You also might like to uncomment the USB_DEBUG and CDC_DEBUG lines in the config.h #ifdef USB_SERIAL_DEBUG #include "pic_serial.h" #endif If you see the above code you will see two config.h files one in the pic pack include & other in the system includes. where do I find the second one. Is it the same as system.h provided in the souceboost include folder? How to build the above program? Do I have to add the .lib files from the pic_pack library folders? Regards Raghunathan
  20. Ahh thanks. So the output pin just goes high when the cmp is equal to the ref? What I'm trying to do is "see" an analog input value in code not just compare one with another, trying to do this with the comparitor, so does this mean I can only do this with the ADC? if so ill have to choose another device. Thanks Morlan Yes, you need to convert the analog signal to its digital equivalent using the builtin ADC of the PIC and then compare the digital values. Regards Raghunathan.
  21. Hi Moral, The comparators output is always hi or low. No inbetweens. Only the comparator inputs are analog.ie any voltage between Vdd to Vss. It looks from your program that you are doing a software polling to do a compare. If you use a hardware comparator then the comparator output pin will automatically go hi or low. The very purpose of hardware module is to remove the burden of the code on the mcu. Down load the data sheet of the chip & read how to configure the comparator. I have never used a comparator. I don't know if these comparator could be used as operational amps.like a buffer or inverting or non inverting amplifiers so that their outputs are analog. At the top of this forum I have written a program on using the ADC of PIC16F72. The thread is named "programming pic mico using boostc". Have a look at it. Hope its useful. Regards Raghunathan
  22. while(1); in the above program I think this is the mistake. Remove the semicolon. Regards Raghunathan.
  23. Hi a21, I have used 2X resolution for many of my projects. I mostly use ccp interruts for the encoder so that I can use INT0 and timer0 interrupts for other communication & timer applications. Be careful if you are using the timer1 bec' it need first a rising edge for it to increment in the counter. But that may not cause a big error when u will be using a 1024 ppr are above. This is just to inform you. My code will out the encoder counts onto a hyperterminal for you to view the counts. I use hardware uart at 115200 bauds. You can use the PIC16F876 to do this project. I have used ccp1 and ccp2 for interrupts for this program. In the quadratue encoder you have to use 4 wires +5v, A, B, 0v. short ccp1 & ccp2 pins give it to A & the connect B to RC5. ccp1 is confiured for rising interrupt & ccp2 for falling edge. Make sure that u connect a pullup resistor of value less then 1K to the ccp pins. else your ccp pin picks up noise causing false triggers. This program also receives ascii characters to switch ON & OFF suitable relays connected to the respective pins. Connect LEDs to pins used in the switch case of the c-program to see it go ON & OFF by transmitting the appropriate character. I have used a modified header file for Hard ware uart, just for my convenience. If you wish u can use the same. encoder.c #include <system.h> // Set clock frequency to 20MHz. #pragma CLOCK_FREQ 20000000 //set configuration fuse. #pragma DATA _CONFIG, _HS_OSC & _WDT_OFF & _CP_OFF & _PWRTE_OFF & _LVP_OFF // PIC16F87x defaults for hardware USART support #define TX_PORT 0x07 #define TX_TRIS 0x87 #define TX_BIT 6 #define RX_PORT 0x07 #define RX_TRIS 0x87 #define RX_BIT 7 #define e_SPBRG 0x99 #define e_RCREG 0x1a #define e_TXREG 0x019 #define e_TXSTA 0x98 #define e_RCSTA 0x18 #define e_TXIF_PIR 0x0c #define e_RCIF_PIR 0x0c #define e_TXIF_BIT 4 #define e_RCIF_BIT 5 #define MODE (USART_reset_wdt | USART_HW) // specify that we are using hwuart //520 for 9600 baud #define bit_time 260 // though not required for hwuart needs to be there for the lib to work. #include <rs232_driver_modified.h> signed long encoder_counter; unsigned long encoder_counter1; bit encoder_update_flag; bit encoder_sign_flag; unsigned char encoder_bcd_value[10]; /*Interrupt service routine (ISR).On ccp capture interrupt */ void interrupt( void ) { //encoder interrupts 2x resolution. if(pir1.2) //check for ccp1 interrupt(rising edge) { encoder_update_flag = 1; if(portc.5 == 0) { encoder_counter ++; // increment counter } else //else decrement counter. { encoder_counter --; } pir1.2 = 0; //clear ccp1if } if(pir2.0) //ccp2if (falling edge) { encoder_update_flag = 1; if(portc.5 == 1) { encoder_counter ++; } else { encoder_counter --; } pir2.0 = 0; } } //lookup table for getting the ascii values. unsigned char get_ascii(unsigned char z) { unsigned char ascii[10]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39}; return ascii[z]; } // ascii for "+" void sign_plus(void) { puts_no_cr("+"); } // ascii for "-" void sign_minus(void) { puts_no_cr("-"); } void serial_print(void) { //send encoder value. puts_no_cr("$"); // for $ sign if(encoder_sign_flag == 1) { sign_plus(); } else { sign_minus(); } signed char w = 9; while(w > -1) { putc( get_ascii(encoder_bcd_value[w]) ); w--; } cr_lf(); //carriage return line-feed. } /* this function finds & stores bcd value of the variable counter1 (en- coder value) */ void encoder_bcd (void) { encoder_bcd_value[9] = encoder_counter1 / 1000000000; encoder_bcd_value[8] = (encoder_counter1 % 1000000000)/ 100000000; encoder_bcd_value[7] = (encoder_counter1 % 100000000)/ 10000000; encoder_bcd_value[6] = (encoder_counter1 % 10000000)/ 1000000; encoder_bcd_value[5] = (encoder_counter1 % 1000000)/ 100000; encoder_bcd_value[4] = (encoder_counter1 % 100000)/ 10000; encoder_bcd_value[3] = (encoder_counter1 % 10000)/ 1000; encoder_bcd_value[2] = (encoder_counter1 % 1000)/ 100; encoder_bcd_value[1] = (encoder_counter1 % 100)/ 10; encoder_bcd_value[0] = encoder_counter1 % 10; } // The main program starts here. void main() { // set high speed divisor mode and divisor value(64) for 19200 bauds & (129) for 9600 bauds. uart_init(1,10); //for 115200 baud the divisor is 10 unsigned int a; unsigned char control; trisa = 31; //porta.0-4 as inputs.porta.5 as output. adcon1 = 7; //make them digital i/o. trisb = 0b11000001; /* rc0-free i/o,rc1&rc2-ccp pins,rc3-sclk for u1,rc4-sclk for u2, rc5-quadrature pulse of encoder,rc6-7 as tx & rx */ trisc = 0b11100110; portc = 0; portb =0b110000000; porta.5 = 0; //configure option register bits //portb pull-ups(rbpu)(disable)...bit7 //interrupt on falling edge(RB0/int)(intedg)...bit6=0 //tmr0 clk source(tocs)is transition on RA4..bit5=1(we are using tmr0) //tmr0 source edge select(tose) is hi to low transition...bit4=1 //bit3-bit0...don't care. //SO we use option_reg = 0b11101111; option_reg = 0b11111111; // enable interrupts: interrupt control register. // intcon.6=1; enable peripheral interrupts // intcon.7=1; enable global interrupt // intcon.5=1; enable tmr0 overflow interrupt. // intcon.4=1; enable inte (RB0/int) // intcon.3=0; disable rbie (rb port change interrupt) // intcon.2=0; tmr0if // intcon.1=0; intf ( RB0/int flag) // intcon.0=0; rbif // intcon = 0b11110000; //i will enable RB0/int along with ccp1 interrupt. //peripheral interrupt enable register 1. pie1.2 = 1; //enable ccp1(rc2) interrupt, pin13. //peripheral interrupt enable register 2. pie2.0 = 1; //enable ccp2(rc1)interrupt, pin12. /*ccpcon1: capture/compare/pwm control register1. bit3-0.....ccpxm3:ccpxm0: ccpx mode select bits. we will use... 0100 = capture mode, every falling edge. 0101 = capture mode, every rising edge. we can choose any one of the above mode. but we will use 0101 in our project. to get less count use 0110( divide by 4). or 0111 for divide by 16. ccp1con = 0b00000101; //set capture mode in rising edge. */ // yet to config eeprom read/write . encoder_counter = 0; encoder_update_flag = 1; intcon = 0b11000000; ccp1con = 0b00000101; ccp2con = 0b00000100; while (1) { if (encoder_update_flag == 1) // if encoder value was updated in ISR. { encoder_update_flag = 0; if( encoder_counter < 0 ) { encoder_counter1 = (-1)*encoder_counter; encoder_sign_flag = 0; // flag value for negative integers. } else { encoder_sign_flag = 1; // flag value for positive integers. encoder_counter1 = encoder_counter; } encoder_bcd(); // find the bcd values. serial_print(); // send adc value & encoder value via rs232. } /* check for received control character to switch output relays. overrun bit oerr is cleared by resetting cren to enable continuous receive.*/ if(rcsta.1 == 1) //overrun error bit oerr. { rcsta.4 = 0; rcsta.4 = 1; } //flag bit rcif(pir1.5). checks if a character is present in rcreg. if(pir1.5 == 1) { control = rcreg; switch(control) { case 65: //65 is ascii for "A". If "A" switch ON Rly1. portb.2 = 1; break; case 97: //97 is ascii for "a". If "a" switch OFF Rly1. portb.2 = 0; break; case 66: //66 is ascii for "B". If "B" switch ON Rly2. portb.3 = 1; break; case 98: //98 is ascii for "b". If "b" switch OFF Rly2. portb.3 = 0; break; case 67: //67 is ascii for "C". If "C" switch ON Rly3. portb.4 = 1; break; case 99: //99 is ascii for "c". If "c" switch OFF Rly3. portb.4 = 0; break; case 69: //68 is ascii for "E". If "E" switch ON Rly4. portb.5 = 1; break; case 101: //100 is ascii for "e". If "e" switch OFF Rly4. portb.5 = 0; break; case 70: //70 is ascii for "F". If "F" switch OFF all Rlys. portb = 0b11000010; break; case 71: //71 is ascii for "G". If "G" reset encoder. encoder_counter = 0; encoder_counter1 = 0; encoder_update_flag = 1; break; case 72: //72 is ascii for "H". portb.1=1; //power up the ads chip break; case 104: //104 is ascii for "h" portb.1=0; //power down the ads chip break; default: } } } } here is the rs232_driver_modified.h code. PLs paste this file in the include folder. //////////////////////////////////////////////////////////////////////////// // Serial Communications Library //////////////////////////////////////////////////////////////////////////// // Author(s): Andrew Smallridge // Date 15 November 2004 // // Copyright(C) 2004-2006 Andrew Smallridge // Copyright(C) 2004-2007 Pavel Baranov // Copyright(C) 2004-2007 David Hobday // Existing constants predefined for serial hardware driver and software // emulation for the PIC 16F87x, PIC18F2xx and 18F4xx processors. // For hardware support on other PICs the constants must be mapped to // the corresponding register map of the target device //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// // USART driver template arguments and variables //////////////////////////////////////////////////////////////////////////// #define USART_ARGS TX_BIT, TX_PORT, TX_TRIS, RX_BIT, RX_PORT, RX_TRIS, \ e_SPBRG, e_RCREG, e_TXREG, e_TXSTA, e_RCSTA, \ e_TXIF_BIT,e_TXIF_PIR, e_RCIF_BIT, e_RCIF_PIR, MODE //////////////////////////////////////////////////////////////////////////// // The following three sections should be copied to the user's program: // 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. // // Sample PIC18F defaults for software emulated USART support //#define TX_PORT 0xf8b //#define TX_TRIS 0x0f94 //#define TX_BIT 6 //#define RX_PORT 0x0f82 //#define RX_TRIS 0x0f94 //#define RX_BIT 7 //#define e_SPBRG 0x47 //#define e_RCREG 0x48 //#define e_TXREG 0x49 //#define e_TXSTA 0x4A //#define e_RCSTA 0x4B //#define e_TXIF_PIR 0x4C //#define e_RCIF_PIR 0x4C //#define e_TXIF_BIT 4 //#define e_RCIF_BIT 5 //#define MODE (USART_reset_wdt) // // Sample PIC16F87x defaults for software emulated USART support //#define TX_PORT 0x07 //#define TX_TRIS 0x87 //#define TX_BIT 6 //#define RX_PORT 0x07 //#define RX_TRIS 0x87 //#define RX_BIT 7 //#define e_SPBRG 0x99 //#define e_RCREG 0x1a //#define e_TXREG 0x019 //#define e_TXSTA 0x98 //#define e_RCSTA 0x18 //#define e_TXIF_PIR 0x0c //#define e_RCIF_PIR 0x0c //#define e_TXIF_BIT 4 //#define e_RCIF_BIT 5 //#define MODE (USART_reset_wdt) //////////////////////////////////////////////////////////////////////////// // 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 1041 // 9600 baud at 40MHz //#define bit_time 16667 // 600 baud at 40MHz // // **** END OF DEFAULTS USED FOR SOFTWARE USART EMULATION **** // **** START OF DEFAULTS USED FOR HARDWARE USART **** //////////////////////////////////////////////////////////////////////////// // USART hardwareware implementation template argument values //////////////////////////////////////////////////////////////////////////// // variables cannot be passed as template arguments. The following constants map to // the PIC registers and PIC's USART register locations. These constants are // then used by the templated functions. When moving between PIC families the // register mapping must be changed to map to the corresponding physical register // // PIC18F defaults for hardware USART support //#define TX_PORT 0x0f82 //#define TX_TRIS 0x0f94 //#define TX_BIT 6 //#define RX_PORT 0x0f82 //#define RX_TRIS 0x0f94 //#define RX_BIT 7 //#define e_SPBRG 0x0faf //#define e_RCREG 0x0fae //#define e_TXREG 0x0fad //#define e_TXSTA 0x0fac //#define e_RCSTA 0x0fab //#define e_TXIF_PIR 0x0f9e //#define e_RCIF_PIR 0x0f9e //#define e_TXIF_BIT 4 //#define e_RCIF_BIT 5 //#define MODE (USART_reset_wdt | USART_HW) // PIC16F87x defaults for hardware USART support //#define TX_PORT 0x07 //#define TX_TRIS 0x87 //#define TX_BIT 6 //#define RX_PORT 0x07 //#define RX_TRIS 0x87 //#define RX_BIT 7 //#define e_SPBRG 0x99 //#define e_RCREG 0x1a //#define e_TXREG 0x019 //#define e_TXSTA 0x98 //#define e_RCSTA 0x18 //#define e_TXIF_PIR 0x0c //#define e_RCIF_PIR 0x0c //#define e_TXIF_BIT 4 //#define e_RCIF_BIT 5 //#define MODE (USART_reset_wdt | USART_HW) // // **** END OF DEFAULTS USED FOR HARDWARE USART **** //////////////////////////////////////////////////////////////////////////// // Serial Control Flag Bits // // 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 USART_invert are mutually exclusive. // // Sample use: #define MODE USART_reset_wdt | USART_HW // //////////////////////////////////////////////////////////////////////////// // define USART Mode bits used for the MODE parameter #define USART_HW 0x01 #define USART_invert 0x02 #define USART_reset_wdt 0x04 //////////////////////////////////////////////////////////////////////////// // Define the common serial template structure //////////////////////////////////////////////////////////////////////////// #define _USART_TEMPL template < \ unsigned char T_TX_BIT, unsigned short T_TX_PORT, unsigned short T_TX_TRIS, \ unsigned char T_RX_BIT, unsigned short T_RX_PORT, unsigned short T_RX_TRIS, \ unsigned short T_SPBRG, unsigned short T_RCREG, unsigned short T_TXREG, \ unsigned short T_TXSTA, unsigned short T_RCSTA, unsigned char T_TXIF_BIT, \ unsigned short T_TXIF_PIR, unsigned char T_RCIF_BIT, \ unsigned short T_RCIF_PIR, unsigned char T_MODE > //////////////////////////////////////////////////////////////////////////// // Define the common USART template parameters //////////////////////////////////////////////////////////////////////////// #define _USART_TEMPL_ARGS T_TX_BIT, T_TX_PORT, T_TX_TRIS, T_RX_BIT, \ T_RX_PORT, T_RX_TRIS, T_SPBRG, T_RCREG, T_TXREG, \ T_TXSTA, T_RCSTA, T_TXIF_BIT, T_TXIF_PIR, \ T_RCIF_BIT, T_RCIF_PIR, T_MODE //////////////////////////////////////////////////////////////////////////// // Helpers that hide template arguments //////////////////////////////////////////////////////////////////////////// #define uart_init UART_INIT<USART_ARGS> #define kbhit KBHIT<USART_ARGS> #define getc GETC<USART_ARGS> #define getch GETC<USART_ARGS> #define putc PUTC<USART_ARGS> #define putch PUTC<USART_ARGS> //////////////////////////////////////////////////////////////////////////// // USART Status Bits - Emulates the PIC16F / PIC18F hardware USART implementation //////////////////////////////////////////////////////////////////////////// //============================================= // define USART TXSTA Bits control bits #define u_TX9 0x06 #define u_TXEN 0x05 #define u_SYNC 0x04 #define u_BRGH 0x02 #define u_TRMT 0x01 #define u_TX9D 0x00 //============================================= // define USART RCSTA Bits control bits #define u_SPEN 0x07 #define u_RX9 0x06 #define u_SREN 0x05 #define u_CREN 0x04 #define u_ADDEN 0x03 #define u_FERR 0x02 #define u_OERR 0x01 #define u_RX9D 0x00 //============================================= // define USART PIR status bits #define u_RCIF 0x05 #define u_RXIF 0x05 #define u_TXIF 0x04 //////////////////////////////////////////////////////////////////////////// // KBHIT // // Generic KBHIT handler for hardware and emulated USART // // Returns true with hadware USART when a character is in the RX buffer // Returns true with software emulated USART on detection of a start bit //////////////////////////////////////////////////////////////////////////// _USART_TEMPL char KBHIT(void) { volatile bit l_oerr@T_RCSTA.u_OERR; volatile bit l_cren@T_RCSTA.u_CREN; volatile bit l_rcif@T_RCIF_PIR.u_RCIF; volatile bit l_rx@T_RX_PORT.T_RX_BIT; if (T_MODE & USART_HW) { if (l_oerr) { l_cren = 0; // clear continous receive bit l_cren = 1; // set continous receive bit } return(l_rcif); } else { if (T_MODE & USART_invert) l_rcif = l_rx; else l_rcif = ~l_rx; return(l_rcif); } } //////////////////////////////////////////////////////////////////////////// // GETC // // Generic GETC handler for hardware and emulated USART //////////////////////////////////////////////////////////////////////////// _USART_TEMPL unsigned char GETC(void) { volatile unsigned char l_rcreg@T_RCREG; volatile bit l_rx@T_RX_PORT.T_RX_BIT; unsigned short bit_count; char mask = 0x01; if (T_MODE & USART_HW) { while (!KBHIT<_USART_TEMPL_ARGS>()) // wait for a character if (T_MODE & USART_reset_wdt) clear_wdt(); return(l_rcreg); } else { l_rcreg = 0; while (!KBHIT<_USART_TEMPL_ARGS>()) // wait for a character if (T_MODE & USART_reset_wdt) clear_wdt(); while (mask) { for (bit_count = (-bit_time + 20) /8; bit_count; bit_count++); if (l_rx) l_rcreg |= mask; mask <<= 1; } if (T_MODE & USART_invert) l_rcreg = ~l_rcreg; // delay for but ignore stop bit for (bit_count = (-bit_time *7/8 )/8; bit_count; bit_count++); return(l_rcreg); } } //////////////////////////////////////////////////////////////////////////// // PUTC // // Generic PUTC handler for hardware and emulated USART //////////////////////////////////////////////////////////////////////////// _USART_TEMPL void PUTC(char tx_char) { volatile char l_txreg@T_TXREG; volatile bit l_txif@T_TXIF_PIR.u_TXIF; // 0xf9e.4; volatile bit l_tx@T_TX_PORT.T_TX_BIT; unsigned short bit_count; char mask = 0x01; if (T_MODE & USART_HW) { while (!l_txif); // wait until tx register is empty l_txreg = tx_char; } else { if (T_MODE & USART_invert) { tx_char = ~tx_char; l_tx = 1; // inverted start bit } else l_tx = 0; // start bit for (bit_count = (-bit_time +20)/8; bit_count; bit_count++); while (mask!=0) { if (mask & tx_char) l_tx = 1; else l_tx = 0; for (bit_count = (-bit_time +20)/8; bit_count; bit_count++); mask <<=1; } // do stop bit if (T_MODE & USART_invert) l_tx = 0; // inverted stop bit else l_tx = 1; // stop bit for (bit_count = (-bit_time +20)/8; bit_count; bit_count++); delay_us(1); } } //////////////////////////////////////////////////////////////////////////// // Initialise the UART // // Passed paramters used when hardware USART is used. Dummy values // must be passed for emulated USART //////////////////////////////////////////////////////////////////////////// // BRG_mode - sets the hardware baud rate generator speed mode // BRG_mode == 0 for low speed mode // BRG_divisor - set hardware baud rate generator divisor // Baud rate for software emulated USART set via constants at head of this file _USART_TEMPL void UART_INIT(unsigned char BRG_mode, unsigned char BRG_divisor) { volatile unsigned char dummy; // used to clear the hardware receive register unsigned short bit_count; volatile unsigned char l_spbrg@T_SPBRG; volatile unsigned char l_txsta@T_TXSTA; volatile unsigned char l_rcsta@T_RCSTA; volatile unsigned char l_rcreg@T_RCREG; volatile bit l_tx_tris@T_TX_TRIS.T_TX_BIT; volatile bit l_rx_tris@T_RX_TRIS.T_RX_BIT; volatile bit l_tx@T_TX_PORT.T_TX_BIT; volatile bit l_cren@T_RCSTA.u_CREN; volatile bit l_brgh@T_TXSTA.u_BRGH; if (T_MODE & USART_HW) { l_rx_tris = 1; l_tx_tris = 0; // setup the USART baud rate // configure the divisor l_spbrg = BRG_divisor; l_txsta = 0xa4; // enable transmit function // 7 Async mode - don't care // 6 8 bit selection // 5 Enable TX // 4 SYNC - Async mode // 3 not implemented // 2 BRGH - high speed // 1-0 don't care // configure baud rate generator mode High vs Low speed if (BRG_mode) l_brgh = 1; else l_brgh = 0; l_rcsta = 0xb0; // enable the USART receive logic // 7 SPEN - Serial Port Enable // 6 8 bit selection // 5 Don't care // 4 CREN - Enable continuous receive // 3 disable address detection // 2-0 don't care l_cren = 0; // clear continous receive bit l_cren = 1; // set continous receive bit dummy = l_rcreg; } else { if (T_MODE & USART_invert) l_tx = 0; // inverted idle (stop) bit else l_tx = 1; // idle (stop) bit l_rx_tris = 1; l_tx_tris = 0; for (bit_count = (-bit_time)/8; bit_count; bit_count++); // setup the USART baud rate l_spbrg = BRG_divisor; l_txsta = 0xa4; // enable transmit function l_rcsta = 0x00; // enable the USART receive logic } } void gets(char *destination) { while ((*destination++ = getc()) != 0x0d); // wait until tx register is empty *--destination = 0; } void puts(char *source) { while (*source != 0) // wait until tx register is empty putc(*source++); putc(0x0d); putc(0x0a); } void puts_no_cr(char *source) { while (*source != 0) // wait until tx register is empty putc(*source++); } void cr_lf(void) { putc(0x0d); putc(0x0a); } void cr_lf_8_e_1(void) { txsta.0 = 1; putc(0x0d); txsta.0 = 0; putc(0x0a); } The encoder value can be viewed on a hyper terminal. Actually u can use just one interrupt pin ie. say ccp1 alone to get 2x res. by changing the config of the interrupt from rising to falling(ie. toggling) in the ISR itself. If u are interested I can give u the code. Regards Raghunathan.
  24. Try sending without the timer interrupt & check it up just to rule out the timing problem else you might be writing into the TXreg to often before one transmit is completed. regards Raghunathan.
  25. Hi, Use the test program below. Here b0 is a character varable assuming values 0 - 255 that gets displayed on the LCD. b0 could be your adc variable which gets updated in the adc function.... if adc is 10bit declare variable as int etc. The lprintf commands can be seen in the source boost user manual. Pls down load the latest version of 2k free C compiler/IDE. You can find the user manual in the help menu of the IDE. #include <system.h> #include "lcd_driver.h" #pragma CLOCK_FREQ 4000000 #pragma DATA _CONFIG, _XT_OSC & _WDT_OFF & _CP_OFF & _PWRTE_OFF #define LCD_ARGS 2, /* Interface type: mode 0 = 8bit, 1 = 4bit(low nibble), 2 = 4bit(upper nibble) */ \ 0, /* Use busy signal: 1 = use busy, 0 = use time delays */\ PORTC, TRISC, /* Data port and data port tris register */ \ PORTB, TRISB, /* Control port and control port tris register */ \ 2, /* Bit number of control port is connected to RS */ \ 7, /* Bit number of control port is connected to RW */ \ 3 /* Bit number of control port is connected to Enable */ void main() { unsigned char b0; lcd_setup(); while(1) { for(b0=0;b0<256;b0++) { lcd_clear(); lprintf("4Bit test :-)"); lcd_gotoxy(0,1); lprintf("%d",b0); delay_ms(255); } } } Regards Raghunathan.
×
×
  • Create New...