Jump to content

Prefekt

EstablishedMember
  • Content Count

    20
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Prefekt

  • Rank
    Regular
  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;
  2. Hi, I use the PIC12F675 or PIC 12F629 for this. Do you have an sample code with the timer? regards, Volker
  3. Hi, I want to meassuring the high pulse of an frequency. The high puls could be between 0,5 and 2ms and I need the excacly worth of the high pulse time. Has anybody an Idea how to meassure frequency and/or the hight pulse time? thanks Volker
  4. 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
  5. Hello, I'm stored values in the internal EEPROM from a 16F876. After a reset are the values sometime corrupted oder the values are not the same. Somtimes after a reset, the values are ok? Can anybody explain me why and how I can store my values right in the internal EEPROM? Thanks Volker
  6. 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.
  7. 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
  8. Hello, where can I found an simulator for the pic? Thanks Prefekt
  9. @Joan: Thank's, this was very helpful... @All Has anybody code for a serial connection? The examples on the example page dosn't work! Thanks Prefekt
  10. 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
  11. Has anybody implementet an DCF77 receiver with a pic? cu Prefekt
  12. 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
  13. Hello, I've a simple question about the porta. I've making six LED's on the porta of a PIC16F876. The code is the follow: trisa=00000000b; porta=00111111b; On the output, the LED 1,2,3,4,6 are on, but the LED 5 (RA4) is off, why? Regards Prefekt
  14. Hello, the sampel DS1302 RTC dosen't work, why. I've mailing the author Don Cramer, but no answer is comming... The only change I made is: rst_pin = 0 on porta clk_pin = 1 on porta data_pin = 2 on porta an i have the output from the rtc display on LED's. Has anybody use the code or have a nother code for the ds1302? thanks
  15. 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
×
×
  • Create New...