Jump to content

fransp

EstablishedMember
  • Content Count

    48
  • Joined

  • Last visited

Posts posted by fransp


  1. Hi Frans,

     

    Cheers for the post.  You're right the ANSEL address is quoted out, this was done during troubleshooting, it has been included before and timer 2 still not worked.  PR2 was also changed to 10 during troubleshooting, and is normally 255.

     

    I can only think that there is a register some where that is connected to timer 2 that requires configuring correctly for timer 2 to work correctly, either that or when a timer 2 to PR2 match occurs and sets PIR1,TMR2IF, the interrupt routine i.e. if (PIR & 2) is not correct format, although I have changed this into several possible alternatives.

     

    There may be some registers that are defaulted to a certain condition, whereas I want the opposite for my code to work (such as the ANSEL reg which sets pins to analogue as default)....

     

    Any more ideas guys?

     

    Thanks for your help

     

    Paul

     

     

    Hi Paul,

     

     

    How sure are you that the PIC is really running. Why don't you put a blinking character on the display, not too fast, not timed by interrupt :-) but software in your main/while(1)

     

    So then when this character is blinking you now the PIC is running.

     

    In every project I always try to have a free pin, so I can put a LED/ or scope on it and watch the activity.

     

    I will search further because in my current project Timer2 is on the menu too, although the interrupt loopt is running here on a F874 [ That is all I have at the moment. ]

     

    Late note: In thr tmrhandler you have this FSR, INDF saving and restoring. Any particular reason to do that?. Or just a left over from troubleshoot!

     

    With best regards,

     

    Frans.


  2. paul,

     

    Timer 2 is not like timer 0.

    It keeps timing until its value matches that of Timer2s preset register (PR2).

     

    I can't see you loading up PR2 in your code, so the timer will match the PR2 value.

     

    you need:

     

    ....
    volatile char pr2 @ PR2;
    ....
    pr2 = 255;
    ....

    Hope that helps.

     

    Regards

    Dave

     

    Hi Paul,

     

    You are right I found it.

     

    Maybe Dave is right, normally PR is 255 at start-up as the data sheet says.

    But in your code I found a

     

    _PR2 = 10

     

    It is just after the clear_bit (_ANSEL, _ANS6 ).....

     

    I also noticed you commented out the adres of _ANSEL.

     

     

    With best regards,

     

     

    Frans.


  3. Check count declaration. Must be short (for a two bytes short integer) or (count > 1000) will never be true.

     

     

    Hi Paul,

     

     

    I am not familiar wiht the particular chip, but ...

     

    Did you?

    Have the Global interrupt enable flag set to on?

    Have the individual peripheral interrupt enable set to on?

     

    Do not forget to clear the individual peripheral interrupt flag just before leaving the interrupt code, when you have dealt with the interrupt code.

    Depending on the chip, sometimes peripherals wont work with their interrupt flag still set. In these cases you have to clear the flags outside the interrupt loop.

     

    I hope this helps.

     

     

    Frans.


  4. Try this link: Header Files

     

    To keep code well organized, keep the header file in such a way that, if you compile the source code into a library, the header file will require no or small revision.

     

    But take care: some older BoostC version doens´t check header files date (don´t know about current version). And take a look at rs232 header, full of code: why don´t they follow those guidelines?

     

     

    Hi LcSD53,

     

    Thanks for the link. I did a quick read, it may take awhile before I realy understand it.

     

    The last pragraph of the text in the link does not make things better.

     

    I hope I will be cured some day. :-)

    In the mean time it will be trial and error. I guess.

     

    With best regards,

     

    Frans.


  5. Frans,

     

    Its already there.

     

    Select (highlight) the code then press the tab key to increase the indent or shift tab to decrease the indent of the whole block.

     

    Regards

    Dave

     

    Hi Dave,

     

     

    When this holidays week is over I will print the manuals on decent color printer to read while commuting.

     

    Thanks for the wonderfull SourceBoostIDE.

     

     

    With best regards,

     

     

    Frans.


  6. Hi, Dave,Pavel,

     

     

    Additon of a feature which allows you to sent a selected declaration to the header file as a prototype.

    It can be extend to have the external qualification added on demand.

     

    A right mouse feature typically.

     

    A swap source/header exists but this feature does not need the copy/swap/paste maneuver.

     

     

    With best regards,

     

     

    Frans.


  7. Hi Dave,Pavel,

     

     

    Addition of a feature which enable you to indent or outdent a selected segment of code.

     

    Imagine you have just added another other loop to your code and now yo are shifting the code to match you favorite layout.

     

    With best regards,

     

     

    Frans.


  8. Hi Dave, Pavel,

     

     

    Symptom:

    SourceBoostIDE.

    All characters are converted to Upper case when Match Case in Search options is not checked and the search criteria is met.

     

    Wanted behaviour:

    Leave character in their respective case. Use Match Case only as a search criterium.

     

     

    With best regards,

     

     

    Frans.


  9. Frans,

     

    Post it here.

     

    Maybe we will add it to the example code page later.

     

    Regards

    Dave

     

    Hi Dave,

     

    Ok, I have worked out a complete example, including test to validate the method.

    There is plenty of comment to follow what I am doing and for what purpose.

     

    Thanks for having me do this. I enjoyed every mistake of it.

     

    For All,

     

    Here is my implementation of the C2C example about Reading, Writing and Erasing the EEprom under program control.

    There are three routine's for Writing, Reading and Erasing.

    The Main routine is for testing and showing the code is doing what it is supposed to do.

     

    This is the header file.

    #ifndef _EEPROM_READ_WRITE_H_
    #define _EERPOM_READ_WRITE_H_
    
    // General defines, could have been in system.h?
    #define _EEPROM 0X2100
    
    // Definition of device.
    // Example target 16F874, check the Settings/Target...
    // example CLOCK 20MHz, to make delay_ work on time.
    #pragma CLOCK_FREQ 20000000
    // These are needed too, but may vary with the application.
    #pragma DATA _CONFIG, _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_ON & _CPD_OFF & _DEBUG_OFF & _HS_OSC & _CP_OFF
    
    // note: this is actually done at programming the device.
    // change the data to make Test 1 fail.
    #pragma DATA _EEPROM,55
    
    // my handy defines
    // pin handling
    #define in 1	// gate logic
    #define out 0
    #define on 1	// pin logic
    #define off 0
    
    // Prototyping board specific
    // LED is as per prototype board PIC-P40-USB-20MHz by Olimex.
    
    // bit allocations
    volatile bit LED@PORTE.1;
    volatile bit LED_pin@TRISE.1;
    
    // Configuration of pins is done in main.
    
    // Defines for configuration
    // Definition for all analog pins to digital
    #define alldigital 0x06 
    
    #endif //_EEPROM_READ_WRITE_H_

     

    This is de code file:

     

     
    #include <system.h>
    #include "Eeprom_read_write.h"
    
    /* Demonstration of the write eeprom, read eeprom functions. 
    Written in BoostC.
    
    Based on EEPROM routines from C2C example by Petr Mervart.
    
    This demo program was written for a PIC16F874 on a Olimex prototyping board
    type: PIC-P40-USB-20MHz
    I use the Shane Tolmie bootloader and downloader.
    The downloader was modified by Stef Mientky for direct access of the FTDI FT 232BM USB to serial converter.
    OS WinXP.
    
    Documentation:
    C2C example of Petr Mervart.
    PIC16F87XA Datasheet, DS39583B, page 33-36
    
    Note: 	in BoostC :
    		the actual registers are in lower case.
    		the constants are in upper case.
    		viz: clear_bit( eecon1,EEPGD )
    */
    
    // You can fill the eeprom at programming time with 
    // #pragma DATA 0x2100,data,<data>
    // see: .h
    
    void eeprom_write ( char adresa , char data )  //write to eeprom
    {
    // we check for a writing finish at the end.
    
    eeadr = adresa;					// the address
    eedata = data;						// the data
    
    clear_bit( eecon1,EEPGD ); 		 // make sure we do write to data memory.
    set_bit( eecon1,WREN );			// enabel writing.
    //	clear_bit( intcon , GIE );			// disable interrupts when using them	
    asm{ 
    	movlw	0x55 					// special sequence to unlock programming.
    	movwf	_eecon2 			
    	movlw	0xAA 
    	movwf	_eecon2
    	}
    
    set_bit( eecon1, WR );     		// start writing. 
    while( test_bit( eecon1 , WR )); 	 // cycle until WR reg. eecon1 = 1 (writing...)
    clear_bit( eecon1, WREN );			// disable writing.
    clear_bit ( pir2 , EEIF );			// datasheet says clear also interrupt EEIF
    //	set_bit( intcon , GIE );			// enable interrupts when using them
    
    }
    //
    
    
    char eeprom_read( char adresa ) 		 // read from eeprom
    {
       eeadr = adresa;					// the address
       
       clear_bit( eecon1,EEPGD ); 		// make sure we read the eeprom
       
       set_bit( eecon1, RD );   			// start reading
       return eedata;						// return the byte
    }
    //
    
    
    
    //The original EERPOM_NULL was rewritten to this eraser.
    
    void eeprom_erase ( char adresa , char size )           // erase eeprom
    {
    char i;
    for (i = 0; i < size; i++ )
      	 {
    		eeprom_write( adresa+i , 0 );
    	}
    }
    //
    
    void main()
    {
    char i,j,k,m;
    
    // Configuration as needed for my prototype board.
    
    // to use analog ports as digital 
    clear_bit ( trise, PSPMODE );	// have to switch off slave port pins in E
    adcon1 = alldigital;			// have to set the analog/Vref/digital selection.
    
    // define direction of LED pin.
    LED = off;						// first put it off i.e. inactive state.
    LED_pin = out;					// then switch it to ouput.
    
    // end configuration.
    
    
    // The Tests.
    // I have no LCD or serial com ready for the proto board.
    
    // Test 1: This will test the #pragma _EEPROM and reading of the eeprom.
    // It will lit the LED when test passes i.e. data written is data read.
    // else it will blink the LED 5 times in 2 sec interval.
    
    // Put something in the eeprom, see .h
    
    // flash the test number
    k = 1;
    while ( k > 0 )
    		{
    			LED = on;
    			delay_ms(100);
    			LED = off;
    			delay_ms(200);
    			k--;
    		}
    delay_s(1);
    
    j = eeprom_read ( 0 );
    
    if ( j == 55 )
    {	LED  = on;
    	delay_s(5);
    }
    else
    {
    	k = 10;
    	while ( k > 0 )
    		{
    			LED = !LED;
    			delay_s( 1 );
    			k--;
    		}
    }
    LED = off;
    delay_s ( 2 );
    
    // Test 2. This test will test the writing of the eeprom
    // It will write one byte and read it back.
    // It will lit the LED when the test passes else it will blink.
    
    // flash the test number
    k = 2;
    while ( k > 0 )
    		{
    			LED = on;
    			delay_ms(100);
    			LED = off;
    			delay_ms(200);
    			k--;
    		}
     delay_s(1);
    
    eeprom_write ( 1 , 88 );
    j = eeprom_read ( 1 );
    if ( j == 88 )
    {	LED  = on;
    	delay_s(5);
    }
    else
    {
    	k = 10;
    	while ( k > 0 )
    		{
    			LED = on;
    			delay_ms(100);
    			LED = off;
    			delay_ms(100);
    			k--;
    		}
    }
    LED = off;
    delay_s( 2 );
    
    
    // TEST 3. This test will test the erasing of the eeprom
    // It will erase the number of bytes given and read it back.
    // Iy will lit the LED when the test passes else it will blink.
    
    // flash the test number
    k = 3;
    while ( k > 0 )
    		{
    			LED = on;
    			delay_ms(100);
    			LED = off;
    			delay_ms(200);
    			k--;
    		}
     delay_s(1);
     
    // First we add another byte to the eeprom to check for eraser overshoot.
    eeprom_write (2, 0x99 );
    eeprom_write (3, 0x5A );
    eeprom_erase ( 1 , 2); 		//it will erase two bytes starting at address 1.
    
    j = eeprom_read ( 0 );
    i = eeprom_read ( 1 );
    k = eeprom_read ( 2 );
    m = eeprom_read ( 3 );
    
    if (( j == 55 ) && ( i == 0 ) && ( k == 0 ) && ( m == 0x5A ))
    {	LED  = on;
    	delay_s(5);
    }
    else
    {
    	k = 10;
    	while ( k > 0 )
    		{
    			LED = !LED;
    			delay_s(1);
    			k--;
    		}
    }
    // signal end.
    k = 20;
    while ( k > 0 )
    		{
    			LED = !LED;
    			delay_ms(50);
    			k--;
    		}
    LED = off;
    // End of Tests.
    }

     

    Enjoy, like I did.

     

     

    With best regards,

     

     

    Frans.


  10. Hi Dave, Pavel,

     

     

    Report of misleading error after compiling.

     

    I made a typo in a sub declaration, like this:

     

    char eeprom_read(cahr adresa) // read from eeprom

     

    The compiler says it is missing the right parenthesis.

     

    If you can solve this, that would be fine.

     

    With best regards.

     

     

    Frans.


  11. Frans,

     

    #pragma DATA can be used to set EEPROM memory when the device is programmed. Thats because the PIC EEPROM is mapped to some addresses that can be accessed through the programming interface.

     

    To read and write EEPROM at run time you need to write some code.

    There is plenty of code about that does this: eeprom example

     

    This code is wrtten for old C2C compiler, maybe you can convert it and share it with others.

     

    Regards

    Dave

     

     

    Hi Dave,

     

     

    Thanks, I wil give it a go and let you know.

     

    With best regards,

     

     

    Frans.


  12. can someone please tell me why this array doesn't work???

     

    int j;

    unsigned char x[40];

     

     

    void array(void)

    {

            for (j=0; j < size; j++)

            x[j]=226 + j;

    }

     

    please help!!

     

     

    Hi hvn0005,

     

    I am not much of a C programmer, but I can see some mistakes in your program.

    You declared J to be an int by adding something to it does not change the type, it stays an int unless something is higher in rank than int.

    You declared X[] to be an array of char to which you want to assign a value of int.

    The other one I see is in the for statement, the end condition goes to something which is not declared here but hopefully elsewhere.

    Even if J was declared a char, the sum 226+40 would make 266, which is bigger than a char can hold.

     

    I hope this helps.

     

    Frans.


  13. Well I need a table in rom. BoostC only supports rom char* text = 'text'

    unfortunately most of my data can not be translated into text.

     

    You can put any data into rom char*. Use '\' and than a number. For example to put 0,1,2,100,255 into rom use:

     

    rom char *ptr = "\0\1\2\100\255";

     

    Regards,

    Pavel

     

    Hi Pavel,

     

     

    Yes , that works.

    The numbers must be decimals.

    A rather long _get, so if one is in tight ROM then avoid small tables.

     

     

    Thanks for helping me out.

     

     

    With best regards,

     

     

    Frans.


  14. How do I get the HIGH and LOW of an asm { label: } inside the asm itself.

     

    You can't do it in BoostC. Why do you need this?

     

    Regards,

    Pavel

     

     

    hi Pavel,

     

    Well I need a table in rom. BoostC only supports rom char* text = 'text'

    unfortunately most of my data can not be translated into text.

     

    Then I thought of doing it in asm{} but came upon this HIGH and LOW not recognized by BoostC, but if you look inside the .asm BoostC generates, you see them being there.

     

    With best regards,

     

     

    Frans.

×
×
  • Create New...