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.

im stupid cos i can do this in a 'C program but not in basic

Status
Not open for further replies.

Ricardoco

New Member
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:

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
 
Re: im stupid cos i can do this in a 'C program but not in b

Ricardoco said:
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:

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..
 
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?.
 
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)
 
Maybe

williB Wrote
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
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 )
 
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
 
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
 
some errors

it has 15 errors :D
 
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
 
hmmm ...i had that same problem when i used the dos version of Mpasm... you are using the windows version ? right
 
dos version

i am using the windows version im affraid :(
 
yup

yes i used notepad (did i have to save it somewhere other than my desktop???
 
no the desktop is a good place for it..
i dont know what to tell you..
the problem was mpasm could not find the .inc file
 
Status
Not open for further replies.

Latest threads

Back
Top