I am looking for a simple guide to show me how I can connect my PIC16F88 to my computer. I want to start out simple, such as turning an LED on using my computer, but eventually get into more difficult stuff, such as controlling an LCD. Is there a simple schematic I can follow to achieve this? Thanks, Gman22
you've got to know a couple of things first: 1. how do I program a PIC 2. how do I get my computer to send information over RS232 3. how do I connect my PIC to the MAX232 4. how do I get my PIC to understand what the MAX232 tells me What programming languages are you using? BASIC for on the chip, C++ for on your computer? anyways, just found this: http://www.oz1bxm.dk/PIC/628uart.htm might be helpful, but I'm not sure, coz' I don't know what you want to know
what? I know, everything will be converted to assembly language anyways, so you can better use it right away, that's why I showed him that tutorial, and not one using PICBASIC
For 12 and 14 bit core PICs, whose architecture and instruction set is designed for assembler, I'd recommend assembler. They don't have the resources or the instruction set for C to be compiled anywhere near as well as asm. Depends on your application really, but especially for beginners, why learn anything other than asm - you'll understand your device a lot better that way.
yeah, that's right, I started with PICBASIC because I already used BASIC for some other stuff, like my old Commodore PET, and the almighty C64 (and graphic calculator and stuff) but when I started to try to learn assembly language I realised how simple the chip actually was... It's really not that hard to understand Though, for hobby use, I still recommend BASIC... The assembly language coming out of Proton IDE (no offence to MPLAB, honestly) is actually quite clean, and I haven't had enaugh space on my chip so-far, or speed problems because of bad code... I'd love to get on with assembly language though, but I'm not as fast with that as I am with PICBASIC. Haven't really seen a decent Assembly language for PIC tutorial yet...
Okay, thanks for the posts so far. That schematic looks simple enough to follow. I will try to build it as soon as I have time, and let you know if it works. I know how to program a PIC, and I have a programmer, so that is no problem. I would prefer to program in assembly becuase it just seems right to do so. I do have some more questions though: For the PIC 16F88, I use pin 8(RX) and pin 11(TX), correct? Do I need to use an external oscillator, or will the internal one suffice? Can someone explain in layman's terms what the MAX232 is actually doing? Thanks, Gman22
Are you suggesting that the PIC does the compiling? Huh? I agree...but I still don't know what you mean above.
I think he means the optimisation process which C code undergoes when it is converted to ASM isn't very good with PICs.
Yep, that's what I mean - the optimisation is made worse by the fact that the instruction set for the smaller PICs is so small. It means that the compiler has to use a relatively long winded method compared to something a human could create (we can see the bigger picture...)
That's what I thought, but I couldn't tell. You know some guy on Slashdot really thought there was no point in anything but assembly, from anything from UCs to modern enterprise level applications. A good example of how electrical engineers are not at all qualified to talk about software engineering.
Ok, well I made the circuit, and programmed the PIC with the code I found on the internet below. I connected it to my serial port, gave it power, opened HyperTerminal, setup the connection, and nothing happened. How is this supposed to work? Is the code bad? Code: errorlevel -302 include p16f88.inc ; __config _CP_OFF & _INTRC_IO & _WDT_OFF & _PWRTE_ON & _LVP_OFF & _BODEN_OFF org 0x0004 ; Use internal oscillator and wait for it to settle movlw B'01110000' ; 8Mhz 4Mhz = B'01100000' bsf STATUS, RP0 movwf OSCCON lp BTFSS OSCCON, 2 goto lp bcf STATUS, RP0 main bcf STATUS,RP0 bcf STATUS,RP1 clrf PORTA clrf PORTB ; RB2 - Incoming Data RX ; RB5 - Outgoing Data TX movlw B'11011111' bsf STATUS,RP0 movwf TRISB ; 8MHz for 2400 baud rate ; See http://www.picbasic.co.uk/forum/showthread.php?t=214 movlw 0xCF movwf SPBRG ; 8-bit asych mode, high speed uart enabled movlw 0x24 ; BRGH=1 20=BRGH=0 movwf TXSTA ; Serial port enable, 8-bit asych continous receive mode movlw 0x90 bcf STATUS,RP0 movwf RCSTA loop1 movlw 0x74 ;'t' call putc movlw 0x65 ;'e' call putc movlw 0x73 ;'s' call putc movlw 0x74 ;'t' call putc movlw 0x0D ; CR call putc movlw 0x0A ; LF call putc ; remove next line and program will echo input from PC goto loop1 loop2 nop getc btfss PIR1,RCIF goto getc movf RCREG,W call putc goto loop2 putc btfss PIR1, TXIF goto putc movwf TXREG return end Gman22
Well considering all the code gets translated to the same machine code, the end result is always the same.
The config line has been commented out, which probably means the code isn't running as the config word is trying to use the internal oscillator. It's poor code though. Write it from scratch!
Ok, I'm not using an external crystal, although I have one if I need to use it. The config was set to use an external crystal, but I changed it to internal, and it still didn't work. Can you explain what makes the code poorly written? Gman22 Edit: Nevermind. Call me an idiot, but I used the wrong numbering scheme for the pins on the MAX232...I will test it out later with the correct pins, and I'm sure it should work. Edit 2: Thanks for all the help. Everything works fine now.