Hi,
I've been playing around with a 16F88 for the past week or so, and have had quite a lot of sucess with it. I intend to use this uC in a piece of test equipment, and so far I have learnt a lot about this chip.
I am communicating with a PC via serial and interfacing it with a program I am writing in C#. This is also coming along nicely.
Ok the problem I am having is with the sending and recieving of data. I need to transmit the logic (on/off) status of switches, but transmitting the port 'byte' (i don't know how else to call it - the binary string that represents the PORT register) which contains the bit status (set or unset) appears at my PC as a character (letter/symbol). Presumably the PC is converting the packet, but I would like the 'raw' data (hex string or whatever) so I can convert to binary and determine which switches are being pressed.
If that still makes sense (sorry for the waffle!), I have tried to convert the characters the PIC is sending back to binary, but the resulting unicode for the character does not tie up with the byte I KNOW is being sent.
So far I have been getting around this problem by individually checking the switch status of the port, and transmitting 1 or 0 characters instead... because this is done sequentially in a specific order (and loop), I know the first digit is switch one, second is two, etc:
the 'call send' part just refers to a macro that moves the w to TXREG and implements a wait cycle while the packet is sent.
However I am at the point where I am trying to optimise the code, and 8 parts of code like this in a loop is pretty messy. I'm hoping someone knows a more efficient way to do this (how to send a complete byte of them all), where I don't have to try and convert dodgy characters (or at least suggest a better way to covnert them in C#!!!)
The second question/problem I am having is somewhat similar to above. It relates to send A/D data via the same serial connection. I am having to transmit the BITS of the ADRESH and ADRESL registers seperate and re-compile them into a number at the PC. I am hoping the method for problem 1 will solve this one.
The other issue is that due to switching noise the ADC data is very innaccurate, and I am told (by the data sheet and others) that I should put the uC into SLEEP mode while the conversion takes place and then wake up with the A/D interrupt.
However I am unsure how to proceed, as I have not messed around with interrupts that much (at least not in this program) and in addition I am using a bootloader - which means the 0x04 memory space is already taken up by a 'goto main program' word, rather than an interrupt service routine.
Having the program 'fall' through the interrupt serivce routine into the main program on startup doesn't really cure the issue. I was hoping that someone had an idea how to proceed with using a bootloader and maintaining interrupt support - so I had an idea what the ACTUAL problem is (rather than "what is wrong? the ISR, the init, the ADC, the SLEEP?")... I'd like to start eliminating the posibilities.
I am writing my PIC's program in assembler, it seems easier than trying to learn PIC C or something else, and I have tried for the past few days to search for similar issues/sample code.
I'm not expecting anyone to do it for me, but a few pointers or at least some reassurance I am going about things the right way would really be helpful...
I've attached the ASM source code I am working with... some of it is commented out, some is probably wrong at this point, I can't quite remember (and I can't test it because I blew up my 16F88's ICSP data port and didn't realise until I wiped it this morning xD - waiting for RS to deliver another...)
Thank you very much for reading if you spent the time to sift through the waffle in this post! Haha...
Turkish.
I've been playing around with a 16F88 for the past week or so, and have had quite a lot of sucess with it. I intend to use this uC in a piece of test equipment, and so far I have learnt a lot about this chip.
I am communicating with a PC via serial and interfacing it with a program I am writing in C#. This is also coming along nicely.
Ok the problem I am having is with the sending and recieving of data. I need to transmit the logic (on/off) status of switches, but transmitting the port 'byte' (i don't know how else to call it - the binary string that represents the PORT register) which contains the bit status (set or unset) appears at my PC as a character (letter/symbol). Presumably the PC is converting the packet, but I would like the 'raw' data (hex string or whatever) so I can convert to binary and determine which switches are being pressed.
If that still makes sense (sorry for the waffle!), I have tried to convert the characters the PIC is sending back to binary, but the resulting unicode for the character does not tie up with the byte I KNOW is being sent.
So far I have been getting around this problem by individually checking the switch status of the port, and transmitting 1 or 0 characters instead... because this is done sequentially in a specific order (and loop), I know the first digit is switch one, second is two, etc:
Code:
movlw '0'
btfsc PORTA, 0 ;check if switch 1 is being pressed
movlw '1'
call send
the 'call send' part just refers to a macro that moves the w to TXREG and implements a wait cycle while the packet is sent.
However I am at the point where I am trying to optimise the code, and 8 parts of code like this in a loop is pretty messy. I'm hoping someone knows a more efficient way to do this (how to send a complete byte of them all), where I don't have to try and convert dodgy characters (or at least suggest a better way to covnert them in C#!!!)
The second question/problem I am having is somewhat similar to above. It relates to send A/D data via the same serial connection. I am having to transmit the BITS of the ADRESH and ADRESL registers seperate and re-compile them into a number at the PC. I am hoping the method for problem 1 will solve this one.
The other issue is that due to switching noise the ADC data is very innaccurate, and I am told (by the data sheet and others) that I should put the uC into SLEEP mode while the conversion takes place and then wake up with the A/D interrupt.
However I am unsure how to proceed, as I have not messed around with interrupts that much (at least not in this program) and in addition I am using a bootloader - which means the 0x04 memory space is already taken up by a 'goto main program' word, rather than an interrupt service routine.
Having the program 'fall' through the interrupt serivce routine into the main program on startup doesn't really cure the issue. I was hoping that someone had an idea how to proceed with using a bootloader and maintaining interrupt support - so I had an idea what the ACTUAL problem is (rather than "what is wrong? the ISR, the init, the ADC, the SLEEP?")... I'd like to start eliminating the posibilities.
I am writing my PIC's program in assembler, it seems easier than trying to learn PIC C or something else, and I have tried for the past few days to search for similar issues/sample code.
I'm not expecting anyone to do it for me, but a few pointers or at least some reassurance I am going about things the right way would really be helpful...
I've attached the ASM source code I am working with... some of it is commented out, some is probably wrong at this point, I can't quite remember (and I can't test it because I blew up my 16F88's ICSP data port and didn't realise until I wiped it this morning xD - waiting for RS to deliver another...)
Thank you very much for reading if you spent the time to sift through the waffle in this post! Haha...
Turkish.
Attachments
Last edited: