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.

Help needed - PLEASE!!!!!

Status
Not open for further replies.

Sunf1ower

New Member
Hi Folks,

I am a mature student training to be a design and technology teacher. For my major project I have had to design and make my own product - foolishly I have gone for a product that needs complex (or maybe not so complex if you know what you're doing) programming.

I am using the 16F818 and need it to, on the press of a button, turn a sounder on for 1 second.

I need it to do more but as I am a complete novice can you help me step by step..........................

Overall my micro will have 4 Inputs and 2 Outputs

Thanking you all in advance,
Kay
 
You need to supply a little more information,

What language are you intending using?
Will the sounder be one that makes sound when a voltage is applied or when it is switched on and off rapidly?
Do you have to use the 16F818? If you switch to an 18 series chip (18F1320 would be ideal) then you can use the free Swordfish basic which will make the programing a lot easier.
Do you have a programmer/debugger or do you have to get that as well, if so then a would be ideal.

Mike.
 
I dont want to be harsh but how are you going to be a teacher for technology at least... i know anyone can do the design part with no special knowledge just skill. But the tech part i would assume to be a teacher you need to know alot... and this is very simple. I suggest you stay a student for a while longer before trying to teach anything.

Also im sure if you answer pommies questions you will get better answers also.
 
Atomsoft - I do not intend to teach electronics I specialise in resistant materials and graphic products

Mike

My tutor said the 16F818 was what I needed, as I have no knowledge and he has, that is what I have brought.

I am intending to use assembly language.
The sounder will make a sound when voltage is applied.
I am using MPLAB
 
I dont want to be harsh but how are you going to be a teacher for technology at least... i know anyone can do the design part with no special knowledge just skill. But the tech part i would assume to be a teacher you need to know alot... and this is very simple. I suggest you stay a student for a while longer before trying to teach anything.

Also im sure if you answer pommies questions you will get better answers also.

Atom, I don't mean to sound harsh, but you are SO wrong about that. Yes anyone can do a crappy design and get away with it because most humans are visually illiterate. Take a look around the web, most of it is ugly and done by blind children. :( I used to have this attitude come into my visual fundamentals class when I taught in university. Most people with that attitude were engineering students who thought art was just fun, easy and anyone could do it. I did fail a few of them, but in hind site was way too nice to them. I wish I had marked them much harder now.

Believe me, I can hold my own programming, and analyzing most circuits, and have confidence I can get most anything to work. Compared to what I need to know to deliver a course in design, that is easy. Real easy.
 
Atomsoft - I do not intend to teach electronics I specialise in resistant materials and graphic products

Mike

My tutor said the 16F818 was what I needed, as I have no knowledge and he has, that is what I have brought.

I am intending to use assembly language.
The sounder will make a sound when voltage is applied.
I am using MPLAB

Sunflower,
I think Mike is right here. How much time do you have in witting assembler for PICs? probably your tutor could do it in assembler, and if he is willing to give you LOTs of help could coach you through. What Mike is suggesting is a much easier way for you to achieve the result on your own. I have watched Mike coach others on this board again and again to a satisfactory completion...

You will probably still get tons of help here if you choose to stay with assembler, but you may wish to think about it.

Where are you located? Are parts readily available?

When is your project due?

EDIT: Kay, you still didn't say how you intend to load the program in the chip. I am guessing your tutor has a programmer?
 
Last edited:
To get started you should start a new project in mplab and add an empty .asm file. Next, copy the contents of the template file 16F818TEMP.ASM found in C:\Program Files\Microchip\MPASM Suite\Template\Code or the equivalent if you installed MPLAB somewhere else. This should give you a project that will build correctly and you can then try writing some code after the line containing the label main. There are lots of examples on the net to get you started and when you get stuck someone on here will be able to help.

You stated you are using MPLAB but that is not a programmer. A programmer is a hardware device that allows you to program the actual chip. Do you have one of these and if so which one?

Mike.
 
Thanks

Thanks for your rapid replies!

I am located in North wales and bought my bits on-line. My tutor and the uni are an hour and a half away and so I am trying to do as much as I can on my own. I have read his book - PIC in Practice and am trying to struggle through!

I will use the programmer at the uni.

And now the really funny part..............I have under 3 weeks to do this!!!!!!

The sounder is just the tip of the iceberg...........I have to then programme my chip to send a remote signal to another unit using an RF600T Tranceiver and then make the chip in that unit turn on the sounder intermittently for 30 seconds.
 
Thanks for your rapid replies!

I am located in North wales and bought my bits on-line. My tutor and the uni are an hour and a half away and so I am trying to do as much as I can on my own. I have read his book - PIC in Practice and am trying to struggle through!

I will use the programmer at the uni.

And now the really funny part..............I have under 3 weeks to do this!!!!!!

The sounder is just the tip of the iceberg...........I have to then programme my chip to send a remote signal to another unit using an RF600T Tranceiver and then make the chip in that unit turn on the sounder intermittently for 30 seconds.

Don't fret, you can do this... :)

Mr Smith's book (1st ed.) was one of the first I read. I think he has a second edition out now? I hope! OK, I see there is a second ed. in 2006. I would not recommend the first edition to anyone. It was so full of mistakes, and he had this *dumb* idea that one should make their own header file for the antique 16F84, which was the chip he introduced in his first book. You can tell him that I am still a bit peeved that I have so many antique 'F84 chips in my collection based on his recommendation. :p

If he still recommends making your own header file for the chip, don't listen. Take Mike's advice and use a COPY of the template file from your install directory. It has the proper MicroChip include file. You can comment out the EEPROM initializations at the bottom of the template for now.

The first program in my edition was flash an LED, as it should be, for it is the 'hello world' of embedded systems. Give that a shot on your own. I don't think you have the hardware at home, so learn to use the simulator in MPLab.

One of the better assembly tutorials on the net is Nigel's. Have a look at his site:



another one I really liked was the elmer site:

Elmer 160 Home Page

If you run into any snags, come back here for direction, or come back when you get the LED flashing. :)
 
Take a look at this it help you get started. Do you have you circuit drawled out.
 
Here you something to get you started. It will build for 16f818 with the changes to It was for 16f628
Code:
 ;**********************************************************************
;
; Tutorial 12.1T - Manchester transmit routine, one byte packets.
;
;**********************************************************************
	list      p=16f818

 __CONFIG   _CP_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _CCP1_RB2 & _DEBUG_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_IO 


	#include <p16f818.inc>


;#define 		TXINV
;invert TX output so inactive is HIGH?




packet_len	EQU 	2		;packet length 1 + 1 address byte

;TX pin is porta, 6

#ifndef 	TXINV
#define 	TXLOW 	BCF	PORTA, 6
#define 	TXHIGH 	BSF	PORTA, 6
#else
#define 	TXLOW 	BSF	PORTA, 6
#define 	TXHIGH	BCF	PORTA, 6
#endif

;***** VARIABLE DEFINITIONS

	cblock 	0x20 			;start of general purpose registers

		ncnt
		bt
		sum
		mtx_buffer
		mtx_buffer1
		mtx_delay		; half_frame delay

		count1			;used in delay routine
		count2
		counta			;used in delay routine
		countb			;used in delay routine
	endc



		org	0x0000
  		goto 	main
		nop
		nop
		nop
		retfie


main		; program starts here
                banksel OSCCON          ; Set oscilator to 4MHz
                movlw   b'01100000'
                movwf   OSCCON


		bsf 	STATUS,		RP0	;select bank 1
		movlw 	0x00
		movwf 	TRISA
		clrf 	TRISB



		bcf 	STATUS,		RP0	;select bank 0
		clrf 	PORTA
		clrf 	PORTB
		call 	mtx_init

Loop
		movlw	0xAA			;set packet address byte to 0xAA
		movwf 	mtx_buffer
		movlw	'N'
		movwf 	mtx_buffer1
		call	mtx_send
		call	Delay20
		movlw	'i'
		movwf 	mtx_buffer1
		call	mtx_send
		call	Delay20
		movlw	'g'
		movwf 	mtx_buffer1
		call	mtx_send
		call	Delay20
		movlw	'e'
		movwf 	mtx_buffer1
		call	mtx_send
		call	Delay20
		movlw	'l'
		movwf 	mtx_buffer1
		call	mtx_send
		call	Delay20
		movlw	' '
		movwf 	mtx_buffer1
		call	mtx_send
		call	Delay20
		goto	Loop

;Manchester subroutines

;    Author:        el@jap.hu
;                   http://jap.hu/electronic/

mtx_init	movlw 	.115 		; 350 usec
		movwf 	mtx_delay
		return
		;

mtx_send
					; send out buffer
outbuf		movlw 	0x14 		; 20xbit1, 1xbit0

header		movwf 	count2
head0		call 	bit1
		decfsz 	count2,F
		goto 	head0
		call 	bit0

		movlw 	mtx_buffer
		movwf 	FSR
		movlw 	packet_len
		movwf 	count1
		movlw 	0xff
		movwf 	sum
		;
outbu0		movf 	INDF,W
		call 	update_sum
		movf 	INDF,W
		call 	outbyte
		incf 	FSR,F
		decfsz 	count1,F
		goto 	outbu0
		movf 	sum,W
		call 	outbyte
					; buffer is sent
		return

update_sum	; fast CRC-8 algorithm with poly x^8+x^5+x^4+1
		; executes in 23 cycles per update

		xorwf	sum,f
		clrw
		btfsc	sum,7
		xorlw	0x7a
		btfsc	sum,6
		xorlw	0x3d
		btfsc	sum,5
		xorlw	0x86
		btfsc	sum,4
		xorlw	0x43
		btfsc	sum,3
		xorlw	0xb9
		btfsc	sum,2
		xorlw	0xc4
		btfsc	sum,1
		xorlw	0x62
		btfsc	sum,0
		xorlw	0x31
		movwf	sum
		return

outbyte		movwf 	bt
		movlw 	8
		movwf 	count2
outby0		rlf 	bt,F
		btfsc 	STATUS,C
		goto 	outby1
		call 	bit0
		goto 	outby2
outby1		call 	bit1
outby2		decfsz 	count2,F
		goto 	outby0
		;
		call 	bit1
		; and 	bit0 - falls through to bit0 subroutine

;send a bit0

bit0		TXHIGH 			; HIGH


		call	mtx_bitdel	; bit time delay

		TXLOW 			; to LOW transition

		call	mtx_bitdel	; bit time delay
		return

;send a bit1

bit1		TXLOW 			; LOW

		call	mtx_bitdel	; bit time delay

		TXHIGH 			; to HIGH transition

		call	mtx_bitdel	; bit time delay
		return

; bit delay modified by NG

mtx_bitdel	movf 	mtx_delay, W
		movwf 	ncnt
ndelaya1	decfsz 	ncnt, F
		goto 	ndelaya1
		return

; end of Manchester routines

;Delay routines

Delay255	movlw	0xff		;delay 255 mS
		goto	d0
Delay100	movlw	d'100'		;delay 100mS
		goto	d0
Delay50		movlw	d'50'		;delay 50mS
		goto	d0
Delay20		movlw	d'20'		;delay 20mS
		goto	d0
Delay5		movlw	0x05		;delay 5.000 ms (4 MHz clock)
d0		movwf	count1
d1		movlw	0xC7			;delay 1mS
		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
hope this helps the code by Nigel Goodwin
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top