Pic16f870

Thread Starter

EricFa

Joined Dec 29, 2010
3
Is there a place where I can find Sample Code for the PIC16F870 from Microchip? Or maybe a tutorial with examples? :confused:
 

Thread Starter

EricFa

Joined Dec 29, 2010
3
I already searched with Google, but it only finds Samples for the PIC 16F84 and not the PIC16F870. :(:(:mad:
Is there any way I can find people, that have experience in programming the PIC 16F870?
 

Markd77

Joined Sep 7, 2009
2,806
Problem is there are hundreds of PICs so there are not too many examples for the less popular ones.
For simple programs it is not too hard to change them from one PIC to the other. If you make the basic changes like anything which refers to the device number then compliing it and reading the errors should guide you in the right direction.
If you have problems, post code, circuit diagram and error reports and we should be able to help.
Ones that you should find lots of examples for are 16F628, 16F877.
16F84 is a bit older and has some differences to the modern PICs so I'd avoid code for that one.
 

t06afre

Joined May 11, 2009
5,934
Do you want to program in C or assembler? Also do you have some demo board. Or are you just using a breadboard. And you do have a programmer (hardware)?
Since a PIC MCU is a building block. It is hard to find general examples. I have some ideas what you can do. But I need to know more about your design limits.
 

Thread Starter

EricFa

Joined Dec 29, 2010
3
@ Markd77:
What is the difference between the PIC16F870 and the 16F628 or 16F877?

@ bertus:
Thanks for the Link!

@ t06afre:
I have an USB & Serial Dual Mode Microchip PIC Programmer
http://www.nbglin.com/usbb.htm
I bought it via Ebay.

I just want some code; someone must have programmed something with the PIC16F870.
 

t06afre

Joined May 11, 2009
5,934
@ Markd77:
What is the difference between the PIC16F870 and the 16F628 or 16F877?
@ bertus:
Thanks for the Link!
@ t06afre:
I have an USB & Serial Dual Mode Microchip PIC Programmer
http://www.nbglin.com/usbb.htm
I bought it via Ebay.
I just want some code; someone must have programmed something with the PIC16F870.
You forgot to tell us which programming language you want to use. I do not think you will get much help this way. So instead let us do like this. You find some projects on the net that you feel you feel match your skill level. If you want post the links here for our opinion. Then you can use this forum if you need help in porting them to your CPU.
 

Tahmid

Joined Jul 2, 2008
343
Hi,
You haven't mentioned which language and compiler you use. So it makes things hard. If you specified that, someone could have just coded something. So, I'll just post a few examples:

All of them are to blink a LED at RB0 (PORTB pin 0). Configuration: 4MHz crystal, XT OSC, Watchdog timer off, Power Up timer off, Code protect off, Brown out detect off, Low voltage program disabled, Data EE read protect off, Flash program write disabled, Background debug disabled. Config 0x3939

mikroC:
Rich (BB code):
void main() {
     TRISB = 0;
     PORTB = 0;
     while (1){
           PORTB.F0 = ~ PORTB.F0; //Invert RB0
           delay_ms(500);
/*Can also be written as:
           PORTB.F0 = 1;
           delay_ms(500);
           PORTB.F0 = 0;
           delay_ms(500);
*/
     }
}
mikroBASIC:
Rich (BB code):
program LEDBLINK

main:
     TRISB = 0
     PORTB = 0
     while true
           PORTB.B0 = not PORTB.B0 'Invert state at RB0
           delay_ms(500)
           'Can also be written as
           'PORTB.B0 = 1
           'delay_ms(500)
           'PORTB.B0 = 0
           'delay_ms(500)
     wend

end.
MPASM (assembler in MPLAB):
Rich (BB code):
    LIST P=16F870
    #INCLUDE <P16F870.INC>
    __CONFIG 0x3939
;    CAN BE WRITTEN AS
;    __CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_OFF & _WDT_OFF & _XT_OSC

    ORG 0x00
    GOTO MAIN

    CBLOCK 0x20
    d1
    d2
    d3
    ENDC

DELAY
            ;499994 cycles
    movlw    0x03
    movwf    d1
    movlw    0x18
    movwf    d2
    movlw    0x02
    movwf    d3
Delay_0
    decfsz    d1, f
    goto    $+2
    decfsz    d2, f
    goto    $+2
    decfsz    d3, f
    goto    Delay_0

            ;6 cycles
    goto    $+1
    goto    $+1
    goto    $+1

RETURN

MAIN
    BANKSEL    TRISB ;GOTO BANK 1
    CLRF    TRISB ;SET PORTB TO OUTPUT
    BANKSEL    PORTB ;GOTO BANK 0
    CLRF    PORTB ;CLEAR PORTB

START
    BSF        PORTB,0 ;SET RB0
    CALL    DELAY
    BCF        PORTB,0 ;CLEAR RB0
    CALL    DELAY

    GOTO    START
END
Hope this helps.
Tahmid.
 

John P

Joined Oct 14, 2008
2,026
The neat thing about the PIC processors, at least the 8-bit ones, is that the programming is the same for all of them. You just have to make adjustments for the features that each chip has or hasn't got. You need to get the data sheets for your particular unit to figure out what's possible on that chip.
 
Thread starter Similar threads Forum Replies Date
P Microcontrollers 6
T Microcontrollers 2
Top