Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 20th November 2004, 11:12 AM   (permalink)
Default im stupid cos i can do this in a 'C program but not in basic

ok the dunce is back, and i just cant seem to get things right so if someone could look at this simple piece of code and tell me why it wont work it would be real nice (simple to you maybe) im taking things real easy and well it compiles but it dosnt work so it must be my understanding is wrong so if you could point me in the right direction there as well it would also be nice :roll:

Quote:

symbol BUTUP = PORTA.0
symbol BUTDN = PORTA.1
BUTVAL Var byte

BUTUP = 0
BUTDN = 0
BUTVAL = 0

TRISA = $FF
TRISB = $00
PORTB = $00

Main:

if BUTUP = 1 THEN BUTVAL = butval +1
IF BUTVAL > 6 THEN BUTVAL = 6
if BUTDN = 1 THEN BUTVAL = butval -1
IF BUTVAL < 0 THEN BUTVAL = 0

Ledson
Ledson:

if BUTVAL > 0 THEN PORTB.0 = 1
if BUTVAL >= 1 THEN PORTB.1 = 1
if BUTVAL >= 2 THEN PORTB.2 = 1
if BUTVAL >= 3 THEN PORTB.3 = 1
if BUTVAL >= 4 THEN PORTB.4 = 1
if BUTVAL = 5 THEN PORTB.5 = 1
if butval = 0 THEN PORTB = 0
Goto Main

end
__________________
In the game of life the fact is, everyone loses, but I sure enjoy playing. ....Asking many questions could make you appear to be a Master! Just Remember Appearances can often be decieving.
Ricardoco is offline  
Reply With Quote
Old 20th November 2004, 12:20 PM   (permalink)
Default Re: im stupid cos i can do this in a 'C program but not in b

Quote:
Originally Posted by Ricardoco
ok the dunce is back, and i just cant seem to get things right so if someone could look at this simple piece of code and tell me why it wont work it would be real nice (simple to you maybe) im taking things real easy and well it compiles but it dosnt work so it must be my understanding is wrong so if you could point me in the right direction there as well it would also be nice :roll:

Quote:

symbol BUTUP = PORTA.0
symbol BUTDN = PORTA.1
BUTVAL Var byte

BUTUP = 0
BUTDN = 0
BUTVAL = 0

TRISA = $FF
TRISB = $00
PORTB = $00

Main:

if BUTUP = 1 THEN BUTVAL = butval +1
IF BUTVAL > 6 THEN BUTVAL = 6
if BUTDN = 1 THEN BUTVAL = butval -1
IF BUTVAL < 0 THEN BUTVAL = 0

Ledson
Ledson:

if BUTVAL > 0 THEN PORTB.0 = 1
if BUTVAL >= 1 THEN PORTB.1 = 1
if BUTVAL >= 2 THEN PORTB.2 = 1
if BUTVAL >= 3 THEN PORTB.3 = 1
if BUTVAL >= 4 THEN PORTB.4 = 1
if BUTVAL = 5 THEN PORTB.5 = 1
if butval = 0 THEN PORTB = 0
Goto Main

end
you havnt defined/declared Ledson , in the beginning.
Maybe..
williB is offline  
Reply With Quote
Old 20th November 2004, 01:30 PM   (permalink)
Default

I'm not familiar with the dialect, but presumably you are defining BUTUP as PortA.0?, and the same with BUTDN and PortA.1?.

But then a couple of lines later you set them as zero?.

Presumably, as this doesn't give an error?, it's redefining the two definitions?.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Reply With Quote
Old 20th November 2004, 01:58 PM   (permalink)
Default Ahhhh

ok this is how it is, i am a bit scared to write in assembler as i had to do that a college (using MASM in hnd software engineering) a few years ago and although i passed the modules it was like having your teeth drilled as far as i was concerned and that was simple to draw three wire frame boxes one inside the other!! so the word assembler strikes the fear of god into me. what i am trying to say is i have a little vellman p8048'1 programmer for 8,18 and 28 pin 300mil dil packages the software that came with it says it cant see the programmer so i found microstudio pro which does see it and i am using that and RE PIC PROGRAMMER to program the pic its all over the place tell me how to start PLEASE or shoot me all i want is a way of programming a pic properly with a language that dosnt require a phd just to understand and break down or modify some examples (basic ones that is)
__________________
In the game of life the fact is, everyone loses, but I sure enjoy playing. ....Asking many questions could make you appear to be a Master! Just Remember Appearances can often be decieving.
Ricardoco is offline  
Reply With Quote
Old 20th November 2004, 03:01 PM   (permalink)
Default

i guess niether mine nor Nigels stab at the problem worked?
Quote:
or shoot me
LOL, i hope it wont come to that..
Quote:
tell me how to start PLEASE
do you want to start in assembler again..??
williB is offline  
Reply With Quote
Old 20th November 2004, 03:11 PM   (permalink)
Default

or you could try googling

c pic programming

turned up a lot of references
williB is offline  
Reply With Quote
Old 20th November 2004, 03:36 PM   (permalink)
Default Maybe

williB Wrote
Quote:
do you want to start in assembler again..??
well i realise that assembler is the way to go just looking at this forum proves that, ive had a look at Nigels page and i must confess it looks like the way to go except for the fact that learning assembler for the pic just seemed like a sledgehammer to crack a nut, i really only want to do some basic stuff like have inputs starting or interupting small routines like delays and loops i thought basic would be the way to go although why they call it basic i have no idea
The english oxford dictionary states
Quote:
BA·SIC or Ba·sic ( P )
n.
A simple programming language.
Yeh right "A" being singular would indicate they are all the same hmmmm ok then
so you think i should start with assembler?? ok ill give it a go...(ive got my own gun )
__________________
In the game of life the fact is, everyone loses, but I sure enjoy playing. ....Asking many questions could make you appear to be a Master! Just Remember Appearances can often be decieving.
Ricardoco is offline  
Reply With Quote
Old 20th November 2004, 03:46 PM   (permalink)
Default

ok good choice let me give you an outline(code ) to get you started
williB is offline  
Reply With Quote
Old 20th November 2004, 03:52 PM   (permalink)
Default

You have got Mpasm.??

http://www.microchip.com/stellent/id...signDocSelect=
williB is offline  
Reply With Quote
Old 20th November 2004, 03:58 PM   (permalink)
Default your good at ths arnt you

Ok ive downloaded the mpasm program and manual i assume you would like me to get my teeth into that
__________________
In the game of life the fact is, everyone loses, but I sure enjoy playing. ....Asking many questions could make you appear to be a Master! Just Remember Appearances can often be decieving.
Ricardoco is offline  
Reply With Quote
Old 20th November 2004, 04:09 PM   (permalink)
Default

this is borrowed from nigel
cut & paste this code tell me wether it assembles..


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

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

	end
williB is offline  
Reply With Quote
Old 20th November 2004, 04:10 PM   (permalink)
Default

save it to a text file with the extention

.asm
williB is offline  
Reply With Quote
Old 20th November 2004, 04:23 PM   (permalink)
Default some errors

it has 15 errors
__________________
In the game of life the fact is, everyone loses, but I sure enjoy playing. ....Asking many questions could make you appear to be a Master! Just Remember Appearances can often be decieving.
Ricardoco is offline  
Reply With Quote
Old 20th November 2004, 04:24 PM   (permalink)
Default

can u cut & paste the .err file here

use the code button
williB is offline  
Reply With Quote
Old 20th November 2004, 04:34 PM   (permalink)
Default the errors

well here they are
Code:
Error[132]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 2 : Unknown processor (16F628)
Error[105]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 3 : Cannot open file (Include File "P16F628.inc" not found)
Error[131]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 4 : Processor type is undefined
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 9 : Found label after column 1. (movlw)
Error[108]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 9 : Illegal character (0)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 10 : Found label after column 1. (movwf)
Error[122]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 10 : Illegal opcode (CMCON)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 12 : Found label after column 1. (bsf)
Error[122]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 12 : Illegal opcode (STATUS)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 13 : Found label after column 1. (movlw)
Error[122]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 13 : Illegal opcode (b)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 14 : Found label after column 1. (movwf)
Error[122]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 14 : Illegal opcode (TRISB)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 15 : Found label after column 1. (movwf)
Error[122]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 15 : Illegal opcode (TRISA)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 16 : Found label after column 1. (bcf)
Error[122]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 16 : Illegal opcode (STATUS)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 19 : Found label after column 1. (movlw)
Error[108]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 19 : Illegal character (0)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 20 : Found label after column 1. (movwf)
Error[122]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 20 : Illegal opcode (PORTA)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 21 : Found label after column 1. (movwf)
Error[122]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 21 : Illegal opcode (PORTB)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 22 : Found label after column 1. (nop)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 23 : Found label after column 1. (nop)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 24 : Found label after column 1. (movlw)
Error[108]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 24 : Illegal character (0)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 25 : Found label after column 1. (movwf)
Error[122]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 25 : Illegal opcode (PORTA)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 26 : Found label after column 1. (movwf)
Error[122]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 26 : Illegal opcode (PORTB)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 27 : Found label after column 1. (goto)
Error[122]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 27 : Illegal opcode (Loop)
Error[131]   C:\DOCUME~1\ADMINI~1\DESKTOP\MYFIRST.ASM 30 : Processor type is undefined
__________________
In the game of life the fact is, everyone loses, but I sure enjoy playing. ....Asking many questions could make you appear to be a Master! Just Remember Appearances can often be decieving.
Ricardoco is offline  
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 11:18 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.