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.

Programming Languages

Status
Not open for further replies.

christophe

New Member
Hey everyone,
Can someone suggest a simple programming language i can learn so i can program a 16F877A that i bough, using MPLAB. Im using it for an enginnering project at college and ive only really used flowsheets before so a fairly simple one would be nice, cheers!!

Chris
 
christophe said:
Hey everyone,
Can someone suggest a simple programming language i can learn so i can program a 16F877A that i bough, using MPLAB. Im using it for an enginnering project at college and ive only really used flowsheets before so a fairly simple one would be nice, cheers!!

Chris

As you've got MPLAB, you've already got the MicroChip Assembler. As it's a RISC chip it's not too hard to learn, only 35 instructions in total, some of which you only rarely use. Have a look at my PIC tutorials at http://www.winpicprog.co.uk, which are based (mainly) on the 16F628, but move easily to the 877.

The only other free language is JAL (Just Another Language), but you should really be reasonably proficient in assembler before using anything else.

Personally I don't use MPLAB, I just use the assembler MPASM, which is installed along with it typing the code using Notepad and then assembling it with MPASM.
 
Thanks for the advice Nigel, you're tutorials look really good, but for tutorial 1 which lines do i need to amend to make the program sutiable for a 16F877A, is it just the 5th and 6th and if so wot do i put it there,
thanks
 
christophe said:
Thanks for the advice Nigel, you're tutorials look really good, but for tutorial 1 which lines do i need to amend to make the program sutiable for a 16F877A, is it just the 5th and 6th and if so wot do i put it there,
thanks

If you look at tutorial 11, this uses an 876/877, you can get the details from there - for one, the config value is different. But you usually need to turn off the A2D converters as well, this is a code snippit from tut 11.
Code:
		BANKSEL ADCON1			;disable A2D
    		movlw   0x06
    		movwf   ADCON1
    		BANKSEL PORTA

I'm not sure if you need to do anything else for the A version, I've not used one - you would need to check the datasheets, MicroChip usually provide a 'migration' sheet - for moving programmes from the 877 to the 877A - that should tell you if you need to do anything else.
 
Does any one happen to know what the config value for a 16F877A - I/P is, as i cant seem to find it on the microchip website. Also what does the I/P at the end stand for??? Cheers
 
The config value depends on your hardware, (using a crystal or a RC?, want MCLR enabled or not? , ...)

The P just means it's a PDIP part.
 
Im using a 4Mhz ceramic resonator and i want memory clear to be enabled, basicly i just want a test program that will work with a 16F877A to check i have got the circuit and the programmer working right
 
christophe said:
Im using a 4Mhz ceramic resonator and i want memory clear to be enabled, basicly i just want a test program that will work with a 16F877A to check i have got the circuit and the programmer working right

WinPicProg very handily gives you the value for __CONFIG when you select the options on screen - for a 16F877A with XT (4MHz) oscillator the value is 0x2909. But in any case, you can simply select your config options in the programmer software after loading the HEX file.
 
I am now using one of you're programs Nigel which has been slightly altered but i still cant get my circuit to work right, Is the program wrong or is there a problemwith my circuit

;Tutorial 1.1 - Nigel Goodwin 2002
LIST p=16F877A ;tell assembler what chip we are using
include "P16F877A.inc" ;include the defaults for the chip
__config 0x2909 ;sets the configuration settings
;(oscillator type etc.)

org 0x0000 ;org sets the origin, 0x0000 for the 16F628,

BANKSEL ADCON1 ;this is where the program starts running
movlw 0x06
movwf ADCON1 ;turn comparators off (make it like a 16F84)
BANKSEL PORTA

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
movlw 0x00
movwf PORTA
movwf PORTB ;set all bits off
goto Loop ;go back and do it again

end
 
I put it in my circuit which has LED on all the port B outputs and nothing happens. My Other LED comes on to show ive got power (Its just connected across the power lines) and ive checked ive got voltages at the chip in the right places. The only thing i can think of that might be wrong is the oscillator its a 4MHz ceramic resonator
**broken link removed**

its connected into CLK0 and CLK1 and has 2 11pF capacitors earthing it, is this right???
 
Last edited by a moderator:
i believe a ceramic resonator already has the proper capitors built-in. The middle pin of the resonator goes to earth and the pins on the sides go to the clock in/out of the 'F677.

you don't need the capaitors on the resonator.
 
As Pike has already said, you shouldn't need external capacitors with a ceramic resonator - they come with three pins, and include them internally, the middle pin been the ground connection of the capacitors.

If your resonator only has two pins, it's probably not the correct type.
 
which is the best resonator to use then?? or should i change to a crystal, Is there any in the farnell online catalogue that would do??? Also am I still alright with 4MHz
 
christophe said:
which is the best resonator to use then?? or should i change to a crystal, Is there any in the farnell online catalogue that would do??? Also am I still alright with 4MHz

I mostly use crystals, although I have used the occasional ceramic resonator. 4MHz is fine, I usually use either 4MHz or 20MHz, but be aware that for 4MHz you set the oscillator to XT and for 20MHz to HS.

I might also mention that the first tutorial, which you quoted, flashes the LED's far too fast to see any flashing - the second one explains why, and modifies the first routine.

If you have access to a scope, try checking for oscillation on the PIC oscillator pins, you will need to use a x10 probe, a x1 probe will stop the oscillator anyway.
 
I've now got the 4Mhz crystals but do i need to use capacitors with them???
Also in my burning software theres loads of options about setting fuses, i have just left them as default before, do they need altering???
 
christophe said:
I've now got the 4Mhz crystals but do i need to use capacitors with them???
Yes, you need capacitors with them, have a look at my tutorials for the 16F876 and 16F877 boards for examples.
Also in my burning software theres loads of options about setting fuses, i have just left them as default before, do they need altering???

You need to set the options that you are using, particularly important is the oscillator setting - for your 4MHz crystal it should be set to XT. You can also set the options in your assembler file, it's the __config line which does it, my tutorials do this to keep things easy (and it's recommended by MicroChip).[/quote]
 
Ive now got my crystal in and the capacitors and programmed my chip with the following program, which is the 16f877a template from microchip and a small led loop from one of you're programs nigel. my programmer says its programmed ok but it still does'nt work in my circuit, wot could i be doing wrong???

;**********************************************************************
; This file is a basic code template for assembly code generation *
; on the PICmicro PIC16F877A. This file contains the basic code *
; building blocks to build upon. *
; *
; If interrupts are not used all code presented between the ORG *
; 0x004 directive and the label main can be removed. In addition *
; the variable assignments for 'w_temp' and 'status_temp' can *
; be removed. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PICmicro data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files required: *
; *
; *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
; *
; *
;**********************************************************************


list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions

; __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF

; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.


;***** VARIABLE DEFINITIONS
;w_temp EQU 0x71 ; variable used for context saving
;status_temp EQU 0x72 ; variable used for context saving
;pclath_temp EQU 0x73 ; variable used for context saving

ADDRH equ 0x72
ADDRL equ 0x71
DATAADDR equ 0x7D
COUNT equ 0x73

Data1 equ 0x20
Data2 equ 0x21
Data3 equ 0x22
Data4 equ 0x23
Data5 equ 0x24
Data6 equ 0x25
Data7 equ 0x26
Data8 equ 0x27


;**********************************************************************
ORG 0x000 ; processor reset vector

nop ; nop required for icd
goto main ; go to beginning of program

main

;setup RAM data
BANKSEL Data1
movlw 0x11
movwf Data1
movlw 0x22
movwf Data2
movlw 0x33
movwf Data3
movlw 0x44
movwf Data4
movlw 0x55
movwf Data5
movlw 0x66
movwf Data6
movlw 0x77
movwf Data7
movlw 0x88
movwf Data8

movlw 0x04
movwf COUNT


;setup pointers
movlw 0x00
movwf ADDRH
movlw 0x73
movwf ADDRL
movlw 0x20
movwf DATAADDR



BSF STATUS,RP1
BCF STATUS,RP0
movf ADDRH,W
movwf EEADRH
movf ADDRL,W
movwf EEADR
movf DATAADDR,W
movwf FSR

LOOP
movf INDF,W
movwf EEDATA
incf FSR,F
movf INDF,W
movwf EEDATH
incf FSR,F
bsf STATUS,RP0
bsf EECON1,EEPGD
bsf EECON1,WREN
bcf INTCON,GIE

;Required Sequence
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1,WR
nop
nop

bcf EECON1,WREN
bsf INTCON,GIE
bcf STATUS,RP0
incf EEADR,F
decfsz COUNT,F
goto LOOP


goto prog

prog
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
movlw 0x00
movwf PORTA
movwf PORTB ;set all bits off
goto Loop ;go back and do it again




END ; directive 'end of program'
 
For a start, you have it set to use an RC oscillator (set in the __config line), so it won't be oscillating. I would suggest replacing the config line with '__config 0x2909', which sets all options off, and XT oscillator.

There's also a tremendous amount of rubbish in that file, only a tiny amount of which is needed. If you use my tutorial file, simply replacing the __config line as above, change the two references to 16F628 to 16F877A, and remove the line 'movwf CMCON', it should all work OK.

Bear in mind though, this first tutorial doesn't actually 'work', it's not meant to - it leads into the next version which corrects it's main failing. If you have a scope it works fine, but with LED's it appears not to 'work'.
 
thanks for all you're help nigel but it still aint got it to work!! :( I've used ur tutorial 2.1 and changed the things u said. the chips burnt fine but again nothin happens in the circuit. I've checked with a multimeter ive got voltages at the Vdd and that my switches produce a signal, but i aint gettin ne output. I also checked the voltage between the positive rail and the CLK0 which was 3.98V then between positive and CLK1 whcih gave me 4.20V i also checked across the 2 crystal terminals and the V was 0 is this correct or is there something wrong???

thanks again for you're help
 
Status
Not open for further replies.

Latest threads

Back
Top