I hate to say this has been a miserable experience, I have had no luck. I am trying to get the blink led program to work. I have had success using my new PICkit2 programmer (as the first non-PICkit2 programmer did not work) with the MPLAB IDE v8.88 code, and it worked and blinks nicely. But when I use PICBasic Pro to code the PIC16F628A it seems fine, but the LED does not blink.
If I use this code in the MPLAB IDE v8.88 and program the PIC16F628A using RB0 as the LED port it works fine. (not my code)
If I then use thisCode:;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; PIC Microcontroller Tutorial Template ; ; ; ; By Brad Slattery 2009 ; ; www.bradsprojects.com ; ; [email protected] ; ; ; ; 'Designing electronic projects, ; ; to spread the name of Jesus' ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NOTE: If you are brand new to programming, then don't concern yourself to ; ; much with all of these initial lines of code. You can read up all about this ; ; at a later date if you wish. I'm sure that you would rather make an LED flash ; ; or make something interesting happen straight away right? ; ; All you have to know for now is that we will be placing our code just underneath ; ; the SETUP label, and then underneath the BEGIN label. it's really quite simple! ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LIST p=16f628a ; tell assembler what chip we are using (if you are using the 16f628a, then include "P16f628a.inc" ; make sure you change this line and the previous line to read p16f628a __config h'3f18' ; sets the configuration settings - internal oscillator, watchdog timer OFF ; Power Up Timer DISABLED, Master Clear DISABLED, Brown Out Detect DISABLED, ; Low Voltage Programming DISABLED, Data EE Read Protect Disabled, ; Code Protect OFF. (this will remain the same for all tutorials) PC equ h'02' ; The program counter will be refered to as PC - The program counter is ; a little counter within the microcontroller to let itself know what line number ; it is upto when running a program. We can make the microcontroller jump to a certain ; line number by changing the value stored in PC. (we will do this in a later tutorial) cblock h'20' ; Within this cblock and endc, we can define our variables. More info on this, later. delay_1 ; These next two lines will set aside 1byte of ram for delay_1 and 1byte for delay_2 delay_2 ; what we will do with these variables is load them with a number each so that we can endc ; count down from that number to zero. when we reach zero, we continue with the program! ; more info on these two variables can be found in the delay routine. org h'0000' ; This line just tells the microcontroller what address to start running our program from. ; It will always be 0000 hex for all the tutorials. movlw h'07' ; This will turn the comparators OFF. movwf CMCON ; (we just want to use the ports as digital ports) bsf STATUS, RP0 ; select bank 1 (to enable us to change the Input / Output status of our ports) movlw b'00000000' ; set PORTB all outputs (A '0' means output, A '1' means input. We can set each movwf TRISB ; We can set each bit individualy. Each port having 8-bits or 8 pins. movlw b'00100000' ; set PORTA all outputs except for bit 5. Bit 5 is an input ONLY pin. movwf TRISA ; It cannot be set to an output! bcf STATUS, RP0 ; select bank 0 setup ; I always have a title labeled 'setup' this is where we set everything up ; i.e. our variables and flags etc.. so they are ready for the main program begin ; This is where our main program starts. bsf PORTB, 0 ; set PORTB pin 0 to a logic 1 (turns the LED on) call delay ; call the delay so that the LED stays on for a while bcf PORTB, 0 ; clear PORTB pin 0 to a logic 0 (turns the LED off) call delay ; call the delay so that the LED stays off for a while goto begin ; and now go and do it all again (it will run in a continuos loop) delay ; here is a nice and simple delay routine movlw d'255' ; copy the maximum number to our working register (decimal 255) movwf delay_1 ; and now copy it from the w register to delay_1 and delay_2 movwf delay_2 ; Now the rest of the routine will focus on counting down to zero. delay_loop ; We come back to this label when we have not yet reached zero. decfsz delay_1, f ; decrement whatever is in delay_1 by 1 and store the answer back in delay_1 goto delay_loop ; if the answer is not zero, then go back to the delay_loop label. but if the decfsz delay_2, f ; answer is zero then decrement delay_2 by one and store the answer in delay_2 goto delay_loop ; if the answer is not zero, then go back to delay_loop label. but if the answer return ; is zero, then we have completed our delay and now we can return to our main program! end ; We always need to have end at the end, even if we don't want the program ; to actually end, it still must be here!
And program the PIC, it does not work. Initially I thought it was the hookup between PBP and the PICkit2, but even when I dump out the hex file and load that manually into PICkit2 and program the PIC it still does not work.Code:' Name : BLINK.pbp ' Compiler : PICBASIC PRO Compiler 2.6 ' Assembler : PM or MPASM ' Target PIC : 16F or 18F types ' Hardware : Non specific ' Oscillator : internal or external ' Keywords : BLINK LED ' Description : PICBASIC PRO program to to blink an LED connected ' to PORTB.0 about once a second ' 'The following program is a simple test to blink an LED on and off. Select a 'device in the dropdown list above, then click the Compile Only button on the 'toolbar to compile the program and generate a hex file. ' Configure pins for digital operation (uncomment as needed). ' These settings are intended as simple examples. For more detail, ' see the appropriate device datasheet for register descriptions. 'ANSEL = 000000 ' 16F88, 16F688, 16F690, 16F88x 'ANSELH = 000000 ' 16F690, 16F88x 'ADCON1 = 000111 ' 16F87x, 16F87xA, 18F452 'ADCON1 = 001111 ' 18F4620 LED VAR PORTB.0 ' Assign name "LED" to PORTB.0 mainloop: High LED ' Turn on LED connected to PORTB.0 Pause 500 ' Delay for .5 seconds Low LED ' Turn off LED connected to PORTB.0 Pause 500 ' Delay for .5 seconds Goto mainloop ' Go back to loop and blink LED forever End
Any help would be greatly appreciated. At this point I am likely missing something obvious, but I have been trying for so long now my eyes are blurry.
Thanks!
Patrick




Bookmarks