Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PicKit2

Status
Not open for further replies.
Those are the "cut and paste" programmers 3v0. No effort to understand the code, just paste it in and be mystified when it doesn't work.
 
If C is taught properly it is an easily understood language. It can be as simplistic as this:

Code:
// blink LED on RA0
void delay(void)
{
          int i = 1000;  // i is a 16 bit integer value
    LOOP2:   
          i = i - 1;
          if (i > 0) goto LOOP2;
}
        
void main(void)
{
          LATA=0xFE; // RA0 is output
   LOOP1:
          PORTAbits.RA0 = 0;  // set RA0 to 0
          delay();            // call delay
          PORTAbits.RA0 = 1;  // set RA0 to 1
          delay();            // call delay
          goto LOOP1;
}
I do not suggest that we revert back to goto's but it might be a bit of a shock to some that it exists.

For the most part C code is what the author makes it. Anything for pure elegance to mud ugly.
 
I like this better less coding

Code:
void main (){
//ANSEL = 0;
PORTA = 0;                 // Initialize PORTA
TRISA = 0;                 // Configure PORTA as output
while(1){
  Delay_Ms(500);
  PORTA.B0 = ~PORTA.B0;
 }
}
 
Last edited:
I am sure most sane people would. The point of the code was stark simplicity. To illustrate that C code can be written that is easy to understand.

me said:
For the most part C code is what the author makes it. Anything for pure elegance to mud ugly.

Pst: Maybe you want to change this line: :eek:

PORTA.B0 = ~PORTA.B0;
 
Last edited:
I have a feeling this is a dumb question, but I've finally gotten together the components and built the circuit suggested by 80be80, and MPLAB IDE is indicating that it's successfully finding and programming the target with a sample program I'm using (adapted from one of Nigel Goodwin's tutorials), but as hard as I try, I can't get the program to run. I tried running the debugger in MPLAB IDE but it's not recognising the chip (a 16F628A) in debugger mode and failing to enter it. Do I need to do something special to get the program to run on the chip? How do I run it independently of the programmer? Unfortunately I don't have a 5V supply other than through the programmer so I haven't been able to try simply powering it independently and disconnecting the programmer.

The test program oscillates output of both port A and B high and low at a frequency of ~4Hz, and I'm testing it by connecting an LED + series resistor between RA0 and Vdd (or between RA0 and Vss, neither work). Am I missing something obvious?

icsp-png.46231
 
Last edited:
Post your code. Without that, you'll get nothing, or wild guesses.

Thanks for the response; the code works, I've tried it with a different programmer (+ pre-assembled demo board) previously. The issue appears to be that the program isn't running. Here it is though:

Code:
;Hello chip program, adapted from http://www.winpicprog.co.uk/pic_tutorial1.htm.

	LIST	p=16F628a		;tell assembler what chip we are using
	include "P16F628A.INC"		;include the defaults for the chip
	__config _BODEN_ON & _CP_OFF & _DATA_CP_OFF & _PWRTE_ON & _WDT_OFF & _LVP_OFF & _MCLRE_ON & _XT_OSC

	cblock 	0x20 			;start of general purpose registers
		count1 			;used in delay routine
		counta 			;used in delay routine 
		countb 			;used in delay routine
	endc
	
	org	0x0000			;org sets the origin, 0x0000 for the 16F628,
					;this is where the program starts running	
	movlw	0x07
	movwf	CMCON			;turn comparators off (make it like a 16F84)

   	bsf 	STATUS,		RP0	;select bank 1
   	movlw 	b'00000000'		;set PortB all outputs
   	movwf 	TRISB
	movwf	TRISA			;set PortA all outputs
	bcf	STATUS,		RP0	;select bank 0

Loop	
	movlw	0xff
	movwf	PORTA			;set all bits on
	movwf	PORTB
	nop				;the nop's make up the time taken by the goto
	nop				;giving a square wave output
	call	Delay			;this waits for a while!
	movlw	0x00
	movwf	PORTA
	movwf	PORTB			;set all bits off
	call	Delay
	goto	Loop			;go back and do it again

Delay	movlw	d'250'			;delay 250 ms (4 MHz clock)
	movwf	count1
d1	movlw	0xC7
	movwf	counta
	movlw	0x01
	movwf	countb
Delay_0
	decfsz	counta,f
	goto	$+2
	decfsz	countb,f
	goto	Delay_0

	decfsz	count1,f
	goto	d1
	retlw	0x00

	end
 
Last edited:
If you use mplab to program you'll also have to release from reset to and change your fuse like Driver said

Code:
__CONFIG   _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top