Jump to content

Prefekt

EstablishedMember
  • Content Count

    20
  • Joined

  • Last visited

Posts posted by Prefekt


  1. Hi,

    my code for adc with the PIC 12F675 works fine with C2C. But now I have the SourceBoost and the compiler tells me, that are any errors in my code. But I cant find any errors...

     

    Here is the part with the ADC

    /*- Variablen ------------------------------------------------------------- */

    char ADCon0@0x1F;

    char ADCon1@0x9F;

    char ADResH@0x1E;

    char ADResL@0x9E;

    short sResult; // 16Bit ADResH & ADResL

     

    /*- Config ---------------------------------------------------------------- */

    //option_reg;

    trisio=001001b;

    //cmcon=7;

     

    /*- Am Anfang den Port ausschalten und 2 sec warten ------------------------*/

    gpio=000000b;

    delay_s(2);

     

    /*- Configure ADC module ---------------------------------------------------*/

    set_bit(STATUS, 'RP0');

    ADCon1 = 00000100b;

    clear_bit(STATUS, 'PRO');

    ADCon0 = 10000001b;

     

    /*- Lüfter erst mal volle Drehzahl -*/

    gpio=000010b;

    delay_s(4);

     

    /*- Programmschleife ------------------------------------------------------ */

    while(1)

    {

    int i=0;

    int iDelay=16;

    int iDelta=CMaxTemp-CMinTemp;

     

    /*- Meßvorgang -*/

    clear_bit (ADCon0,3); // Select RA0

    set_bit (ADCon0,1); // Start AD-Conversion

     

    while ((ADCon0 & 2) == 2)

    {

    nop();

    }

     

    sResult = ADResH;

    sResult <<= 8;

    sResult |= ADResL;

     

    Has anybody an sample for ADC conversation with PIC 12F675 and SourceBoost?

     

    Thanks

    Volker


  2. Hello,

    here is my code to work with the eeprom.

     

    #include <system.h>

     

    //the memory bank 0 should be selected

    void write_flash( char addr, char data )

    {

    //Write flash

    eeadr = addr;

    eedata = data;

     

    set_bit( status, RP0 );

    set_bit( eecon1, WREN );

    eecon2 = 0x55;

    eecon2 = 0xAA;

    set_bit( eecon1, WR );

    while(eecon1&2);

    clear_bit( eecon1, WREN );

    clear_bit( status, RP0 );

    }

     

    char read_flash( char addr )

    {

    //Read flash

    eeadr = addr;

    set_bit( eecon1, RD );

    asm movf _eedata, W

    }

     

    With a little test prg it works fine. But if I call the write functions from my Project, the values are not stored in the eeprom. If I debug my project, somtimes the values for paramter of the function was not overgiven!

    Do you known the problem.

     

    Ragards


  3. Hello,

    I'm thinking also, that is as memory problem.

    Sample Variable definition:

    it work's:

    char a;

    char b;

    char c;

    or

    int i;

    or

    int i;

    char a;

     

    it dosen't works:

    char a:

    char b:

    char c:

    char d;

    or

    int i;

    int j;

    or

    int i;

    char a;

    char b;

     

    Here is a sample Code, that work. If you delete the comment and use the two integer variable it doesen't work....

     

    #include <system.h>

     

    void erase_eeprom();

    void write_eeprom(char adresa,char data);

    char read_eeprom(char adresa);

     

    void main(void)

    {

    char c=0x00;

    char d=0x00;

    char a=0x00;

    char e=0x00;

    char b=0x00;

    char f=0x00;

    char g=0x00;

    char j=0x00;

    /*int i;

    int k;*/

    trisb=00000000b;

    portb=00000000b;

     

    d=read_eeprom(0x0000);

    write_eeprom(0x0001,10101010b);

    d=read_eeprom(0x0001);

     

    if(d==00001111b){

    c=11110000b;

    portb=11110000b;}

    else{

    c=00001111b;

    portb=00001111b;}

    write_eeprom(0x0000,c);

    while(1);

    }

     

    void write_eeprom(char adresa,char data)

    {

    char addr = adresa;

    char dat = data;

     

    asm{

    BSF STATUS, RP1 ;

    BSF STATUS, RP0 ;Bank 3

    BTFSC EECON1, WR ;Wait for

    GOTO $-1 ;write to finish

    BCF STATUS, RP0 ;Bank 2

    MOVF _addr_write_eeprom , W ;Address to

    MOVWF EEADR ;write to

    MOVF _dat_write_eeprom, W ;Data to

    MOVWF EEDATA ;write

    BSF STATUS, RP0 ;Bank 3

    BCF EECON1, EEPGD ;Point to Data memory

    BSF EECON1, WREN ;Enable writes

    ;Only disable interrupts

    BCF INTCON, GIE ;if already enabled,

    ;otherwise discard

    MOVLW 0x55 ;Write 55h to

    MOVWF EECON2 ;EECON2

    MOVLW 0xAA ;Write AAh to

    MOVWF EECON2 ;EECON2

    BSF EECON1, WR ;Start write operation

    ;Only enable interrupts

    BSF INTCON, GIE ;if using interrupts,

    ;otherwise discard

    BCF EECON1, WREN ;Disable writes

    }

    return;

    }

    char read_eeprom(char adresa)

    {

    char addr = adresa;

     

    asm{

    BSF STATUS, RP1 ;

    BCF STATUS, RP0 ;Bank 2

    MOVF _addr_read_eeprom, W ;Write address

    MOVWF EEADR ;to read from

    BSF STATUS, RP0 ;Bank 3

    BCF EECON1, EEPGD ;Point to Data memory

    BSF EECON1, RD ;Start read operation

    BCF STATUS, RP0 ;Bank 2

    MOVF EEDATA, W ;W = EEDATA

    }

    return EEDATA;

    }

    void erase_eeprom()

    {

    EEADR=0;

    while(EEADR<=63){

    EEDATA=0;

    write_eeprom(EEADR,EEDATA);

    }

    }

     

    @asmallri

    I will test to disable the interrupts.


  4. Hello,

    I'm using a 16F876 and the internal eeprom. The write and read at the eeprom works fine. But if I'm using more than three variables like this:

    char cDigit1=0x00;

    char cDigit2=0x00;

    char cDigit3=0x00;

    char cDigit3=0x00;

    the value was not written in the eeprom?

    If I wrote this in my code:

    char cDigit1=0x00;

    char cDigit2=0x00;

    char cDigit3=0x00;

    //char cDigit3=0x00;

     

    it works?

     

     

    my eeprom code is:

     

    void write_eeprom(char adresa,char data)

    {

    char addr = adresa;

    char dat = data;

     

    asm{

    BSF STATUS, RP1 ;

    BSF STATUS, RP0 ;Bank 3

    BTFSC EECON1, WR ;Wait for

    GOTO $-1 ;write to finish

    BCF STATUS, RP0 ;Bank 2

    MOVF _addr_write_eeprom , W ;Address to

    MOVWF EEADR ;write to

    MOVF _dat_write_eeprom, W ;Data to

    MOVWF EEDATA ;write

    BSF STATUS, RP0 ;Bank 3

    BCF EECON1, EEPGD ;Point to Data memory

    BSF EECON1, WREN ;Enable writes

    ;Only disable interrupts

    BCF INTCON, GIE ;if already enabled,

    ;otherwise discard

    MOVLW 0x55 ;Write 55h to

    MOVWF EECON2 ;EECON2

    MOVLW 0xAA ;Write AAh to

    MOVWF EECON2 ;EECON2

    BSF EECON1, WR ;Start write operation

    ;Only enable interrupts

    BSF INTCON, GIE ;if using interrupts,

    ;otherwise discard

    BCF EECON1, WREN ;Disable writes

    }

    return;

    }

     

     

     

    Is this a bug in the compiler?

    Thanks

     

    Volker


  5. Hello,

    I've a Transponder Board that implements a RS232 Interface. This Borad I can connect with my PC and I developed a software the can comunicate with the board.

     

    Now i would like to get the information from the board with a pic. Need I a serial interface IC?

     

    Has anybody a shematic and the C2C Code for a example application?

     

    thanks

    regards

    Prefekt


  6. Hello,

    I've problems with the A/D conversation. When I'am using only AN0/RA0 it works fine. But, when I'm using AN0 and AN1, the value on AN1 is correct, if AN0 has no input. If AN0 and AN1 have Input, the messuring on AN0 is ok, but the messuring on AN1 is incorrect.

     

    And anoterh probelem is that i configure

    trisa = 00000001b;

    if I write

    trisa = 00000011b; the A/D converter is not running

    but I'm using AN0 and AN1 why?

     

    here's the configuration:

    trisa = 00000001b;

    ADCon1 = 10000100b;

    ADCon0 = 01000001b;

     

     

    That's the code to messure AN0:

    void MessureAkkuVoltage()

    {

    /*- Meßvorgang -*/

    ADCon0 = 01000001b; /*- Select RA0 -*/

    set_bit (ADCon0,2); /*- Start AD-Conversion -*/

     

    while ((ADCon0 & 4) == 4)

    {

    nop();

    }

     

    /*- Wert in einer 16Bit Variable zusammenfassen -*/

    iVmess = ADResH;

    iVmess <<= 8;

    iVmess |= ADResL;

                iVmess = iVmess * 2;  

     

     return;

    }

     

    and messuring AN1:

    void MessureChargeCurrent()

    {

    /*- Meßvorgang -*/

    ADCon0 = 01001001b; /*- Select RA1 -*/

    set_bit (ADCon0,2); /*- Start AD-Conversion -*/

     

    while ((ADCon0 & 4) == 4)

    {

    nop();

    }

     

    /*- Wert in einer 16Bit Variable zusammenfassen -*/

    iAmess = ADResH;

    iAmess <<= 8;

    iAmess |= ADResL;

     

    return;

    }

     

    Has anybody an idea?

    Thanks Prefekt


  7. Hello,

    I programming a LCD Interface an a ADC Input. Now I would display the voltage from ADC to my LCD Display!. But I have two values, one in the low byte another in the high byte. How I can convert the binary value to a decimal value?

    Also I think, I must compute: U = Uinput * 5 / 1,024, because the pic can messure 5V with 10Bit (1024), so the PIC can messure 2,8828 mV Steps 5V/1024, right?

    Has anybody implimented a voltage messure and display on a LCD?

     

    Thanks

    Volker


  8. Hello,

    I need a PWM Output on 10 Pins.

    Do anybody write a PWM output on variouse pin's?

    I wrote the folling code:

    while (j <= 4)

    {

     while ( i <= 255)

     {

       set_bit(portb, 1);

       delay_us(200);

       clear_bit(port. 1);

       delay_us(55);

       i=i+1;

     }

     i=0;

     j=j+2;

    }

     

    This code shoud genertae a output frequenze, with e.g. 1Khz with a output for 72,5%on an 27,5%off.

    But the output is not so, why?

     

    thanks

    Prefekt


  9. Hello,

    I'm new in programming PIC with c.

    In one of my first project, I want get information if a spezifield bit is set on input porta e.g. bit 2.

     

    The function input_pin_port_a() is obsolet? Is ther a new function? Ther is the function set_bit().

    May problem is, I have definition trisa = 00001100b; Then i want call a function if porta is xxxx01xxb and xxxx10xxb (x is 0 or 1) How I can do that without to write:

    if (porta == 00000100b or porta == 00000111b ...) ?

     

    thanks

    Prefekt

×
×
  • Create New...