Jump to content


  • Content Count

  • Joined

  • Last visited

Everything posted by davidb

  1. Hi Samith, Not sure what you are trying to achieve but I have made a few subtle changes to your code so that the lower 8-bits of the adc value are placed on Port B. See if that works on your hardware. Regards davidb #include <system.h> #pragma CLOCK_FREQ 4000000 //#pragma DATA _CONFIG, _XT_OSC & _WDT_OFF & _LVP_OFF & _PWRTE_OFF & _CP_OFF unsigned int Read_adc(unsigned char ch); void Adc_init(); void main() { //Initialise PortB trisb = 0; //configure port B portb = 0; //clear port B //initialise portA trisa = 1; //porta as input Adc_init(); while(1) {
  2. Martin, You have defined TEST and then carried out a check to see if is NOT defined. Since this must be false then the variables will not be defined. Change the #ifndef TEST to #ifdef TEST and all should be fine. Regards davidb
  3. Hi, Problem: The following simply test code demonstrates the problem using signed data types and the comparison if (error > limit). Expected Behaviour: To work correctly x should be 1 less than y at the end of the comparison loop. If the code is compiled for a 16F887 then all works as expected with error defined as any data type; signed char, signed short or signed long. If the code is compiled for a 18F4520 then it fails if error is a signed short but works correctly for signed char and signed long. It also works correctly if the limit definition is changed to any s
  4. Also look at the supplied string handling functions supplied with SourceBoost C for further clues. davidb
  5. Hi iiyama87, Unfortunately you cannot directly compare a string with the contents of a string buffer. What you need to do is create a string parser that will process data in your buffer character by character. Try sending and detecting a single character (followed by NULL) first and build on that. All HyperTerminal is doing is receiving and displaying what you sent character by character. Google something like 'RS232 String Parser'. Good luck davidb
  6. Yes, my mistake. I am so used to having more than 8-bits that ADRESL & ADRESH have become ingrained in my mind. Good luck with your code davidb
  7. Spotted another one: hundreds << 4; tens << 4; units << 4; Incorrect syntax and will be optimised out Once corrected will probably compile but whether it will do what you want is another matter! Cheers davidb P.S Beat you to that one as well Reynard!
  8. Hi LowFilter, A few basic errors: Use lower case for registers, port names, tris etc. Use short NOT short int ADRES not defined semi-colon not required after defines One instance of Tempo rather than tempo Good Luck! davidb
  9. Not always strictly true. To quote from PIC18F4520 datasheet: Hope that helps davidb
  10. In case you don't know where to find it (once I spent a long time looking in the devices data sheet and it's not in there) , you can find the address that needs to used when programming the target device and wanting to write to EEPROM as part of this process in the devices "Memory Programming Specification" data sheet from Microchip. BTW: I know this doesn't help with the 0xf000 address question. Regards Dave Dave, The specification states that: The physical address range of the 256 byte data memory is 0000h-00FFh. However, these addresses are logically mapped to address
  11. Microchip document DS41390C defines the physical address range for EEPROM on the 16F1827 as 0x1E000 to 0x1E1FF. SourceBoost PIC16F1827.h defines _EEPROM as 0x1E000 so all would appear to be well but as you point out it doesn't seem to work in MPLAB. However, changing the definition in PIC16F1827.h to 0xf000 seems to allow it to work in MPLAB. Not sure whether it works on a real device though! davidb
  12. Perhaps I have misread your problem but how about something like: if (UTC_hour < offset) local_time = (UTC_hour + 24) - offset; else local_time = UTC_hour - offset; Regards davidb
  13. You haven't told us which part you are using or shown your variable definitions. Also the maximum result from the ADC should only be 0x03ff. Your code for converting adresl and adresh to 16 bits is long winded and unless both tmp_h and tmp_value_m are defined as shorts then it will not work. If you use: tmp_value_m = (tmp_h <<8) | tmp_l; instead then that should work. However, the code would be more efficient if you re-define adresl as a short or alternatively use a union: unsigned short adresult @adresl; then simply copy the result: tmp_value_m = adresult;
  14. This problem also exists on V6.97 #include <system.h> typedef struct { unsigned char DeviceAddress; unsigned char NumRxDataBytes; } TTestStruct; TTestStruct s; void main(void) { s.DeviceAddress = 1; s.NumRxDataBytes = 0x55; if (--s.NumRxDataBytes) { while(1); } } As does this but with a different error: #include <system.h> unsigned char s[] = {1,0x55}; void main(void) { if (--s[1]) { while(1); } } However this works: #include <system.h> typedef struct { unsigned char DeviceAddress; unsigned char NumRxDataBytes; } TTestStruct; TTestStruct s; voi
  15. Rather a lot of code to wade through and I don't have the time so just a few comments: I notice that in your i2c_is_data_ready() function you are clearing the SSPIF interrupt flag several times but have missed it after 'Master Write, Last Byte was Data'. You only need to clear this flag once so re-arrange the code and do it at the beginning and remove all the other instances. Secondly I would recommend that the slave receive function is carried out under interrupt with suitable data and address buffering rather than being polled. I haven't used I2C with the 16F88* family but when usi
  16. Mark, For what you are trying to do you only need: uartTxInterruptHandler(); uartRxInterruptHandler(); in your interrupt function to handle the UART. These two functions handle the transmitting and receiving of characters to and from the PC via the UART entirely under interrupt control. uartRx() and uartTx() are effectively getc() and putc() respectively and access the rxBuffer[] and txBuffer[] buffers used by uartRxInterruptHandler() and uartTxInterruptHandler(). In your main() to send data simply place it in the txBuffer[] using uartTx(). Any data received will be in the
  17. You are including new line characters in your string so try using the continuation character after each line (not tested): rom char *httpHeader1 = "<html>\ <head>\ <title>Tower-Cam Test</title>\ <body>\ <h2>Tower Camera Sensors </h2>\ <p>Battery Voltage goes here:</P>\ <p> Temperature goes here:</p>\ <p>Time goes here:</p>\ </body>\ </html>"; Regards davidb
  18. #pragma DATA 0x300000,0x00,0x02 #pragma DATA 0x300002,0x1a,0x0e #pragma DATA 0x300004,0x00,0x83 #pragma DATA 0x300006,0x85,0x00 #pragma DATA 0x300008,0x0f,0xc0 #pragma DATA 0x30000a,0x0f,0xe0 #pragma DATA 0x30000c,0x0f,0x40 The following uses #pragma config and should produce the same configuration as above:- /* 18F4520 Configuration Words */ /* Internal/External Oscillator config */ #pragma config OSC = HS, FCMEN = OFF, IESO = OFF /* Power & Brown-out Reset Voltage config */ #pragma config PWRT = ON, BOREN = ON, BORV = 3 /* Watchdog Timer config */ #pragma config WDT = OFF, WD
  19. You cannot prototype an inline function. The definition of an inline function must be made before it is first called. Using your example:- inline void DisableTmr2(void) { // } void main (void) { DisableTmr2(); .. .. for (;;) { } } Regards davidb
  20. In addition to the above regarding debouncing, toggling the LED etc. your code has a few basic errors for real life operation (I never use the simulator so I can't comment on that): You have your switch on the wrong pin to use INTF - it should be on RB0 not RB1 Depending on how your switch is connected you will probably need to set the edge direction and possibly the internal pullup in OPTION_REG. PEIE should also be set to enable the interrupts (INTCON = &d0) Regards davidb
  21. Plagiarism in the forum - What next? Looks like a case of lazy cut and paste - couldn't even be bothered to change your name. Come on CheneyJames own up! davidb
  22. After a quick glance I don't see a definition for rcif e.g. volatile bit rcif@PIR1.RCIF; or is this somewhere else? Alternatively use something like !(test_bit(intcon,TMR0IF)) and !(test_bit(pir1,RCIF)) instead of individually mapping bits. rcreg also needs to be read somewhere to ensure that the receive data interrupt flag is cleared. Also how about initialising timer0 and clearing the interrupt flag tmr0if before starting the timer so you know the initial conditions? Regards davidb
  23. Martin, Shouldn't while (Go_Done == 0); be [/code] or while (Go_Done != 0); For 20MHz Oscillator try using a Tad of 16Tosc and Tacq of 4Tad This gives an automatic 3.2uS aquisition time and 9.6uS conversion time Regards davidb
  24. Try recompiling the project first before building. Regards davidb
  • Create New...