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.

16f690 problem

Status
Not open for further replies.

cagri35

New Member
hi i have a code for line follower robot with 16f628a ,im trying to write this code for 16f690 but i cant do that can u help me? here is a code for 16f628a

LIST P=16F628A
INCLUDE “P16F628A.INC”
__CONFIG _XT_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _BODEN_OFF & _LVP_OFF & _DATA_CP_OFF & _CP_OFF

CBLOCK H’20′
SAYAC
IS
BEK
ENDC

MOVLW H’07′
MOVWF CMCON
CLRF PORTB ;comp off

BANKSEL TRISA
MOVLW H’FF’
MOVWF TRISA
CLRF TRISB
BANKSEL PORTB
CLRF PORTB

; PROGRAM
MOVLW D’128′
MOVWF IS
MOVLW D’128′
MOVWF BEK

CYCLE
BTFSS PORTA,1

GOTO STRAIGHT
BTFSS PORTA,0

GOTO LEFT
BTFSS PORTA,2
GOTO RIGHT
GOTO CYCLE

STRAIGHT
BSF PORTB,0
BSF PORTB,2
GOTO CYCLE

LEFT
BSF PORTB,0

;—————————–left MOTOR %50 (PWM)————————
BSF PORTB,2
MOVF IS,W
CALL GECIKME
BCF PORTB,2
MOVF BEK,W
CALL GECIKME

GOTO CYCLE

RIGHT
BSF PORTB,2

;————————right motor %50 (PWM)—————————
BSF PORTB,0
MOVF IS,W
CALL GECIKME
BCF PORTB,0 ;
MOVF BEK,W
CALL GECIKME

GOTO CYCLE

CYCLE
MOVWF SAYAC

CYCLE2
DECFSZ SAYAC,F
GOTO CYCLE2
RETURN
END
 
sorry they are just words in other language you can write other words for these, they are just assignments values for h block h'20',here is a code with different words,but i compliled that on mplab,these codes works in 16f628a ,but these 16f690 i cant do anything with 16f690
 
LIST P=16F628A
INCLUDE "P16F628A.INC"
__CONFIG _XT_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _BODEN_OFF & _LVP_OFF & _DATA_CP_OFF & _CP_OFF

CBLOCK H'20'
COUNTER
IS
BEK
ENDC

MOVLW H'07'
MOVWF CMCON
CLRF PORTB ;comp off



BANKSEL TRISA
MOVLW H'FF'
MOVWF TRISA
CLRF TRISB
BANKSEL PORTB
CLRF PORTB

;PROGRAM
MOVLW D'128'
MOVWF IS
MOVLW D'128'
MOVWF BEK

CYCLE
BTFSS PORTA,1

GOTO STRAIGHT
BTFSS PORTA,0

GOTO LEFT
BTFSS PORTA,2
GOTO RIGHT
GOTO CYCLE

STRAIGHT
BSF PORTB,0
BSF PORTB,2
GOTO CYCLE

LEFT
BSF PORTB,0

;-----------------------------lef MOTOR %50 (PWM)------------------------
BSF PORTB,2
MOVF IS,W
CALL DELAY
BCF PORTB,2
MOVF BEK,W
CALL DELAY

GOTO CYCLE

RIGHT
BSF PORTB,2

;------------------------right motor %50 (PWM)---------------------------
BSF PORTB,0
MOVF IS,W
CALL DELAY
BCF PORTB,0
MOVF BEK,W
CALL DELAY

GOTO CYCLE

DELAY
MOVWF COUNTER

CYCLE2
DECFSZ COUNTER,F
GOTO CYCLE2
RETURN
END
 
Code:
LIST P=16F690
	INCLUDE "P16F690.INC"

	__CONFIG _XT_OSC & _WDT_OFF & _PWRTE_ON & _BOR_OFF & _CPD_OFF & _MCLRE_ON & _CP_OFF

	CBLOCK 0x20
	SAYAC
	IS
	BEK
	ENDC

	MOVLW 0x07
	MOVWF CM1CON0
	CLRF PORTB 		;comp off

	BANKSEL TRISA
	MOVLW 0xff
	MOVWF TRISA
	CLRF TRISB
	BANKSEL PORTB
	CLRF PORTB

; PROGRAM
	MOVLW 0x80
	MOVWF IS
	MOVLW 0x80
	MOVWF BEK

CYCLE
	BTFSS PORTA,1

	GOTO STRAIGHT
	BTFSS PORTA,0

	GOTO LEFT
	BTFSS PORTA,2
	GOTO RIGHT
	GOTO CYCLE

STRAIGHT
	BSF PORTB,0
	BSF PORTB,2
	GOTO CYCLE

LEFT
	BSF PORTB,0

;-------left motor %50 (PWM)---------
	BSF PORTB,2
	MOVF IS,W
	CALL GECIKME
	BCF PORTB,2 
	MOVF BEK,W
	CALL GECIKME

	GOTO CYCLE

RIGHT
	BSF PORTB,2 

;-------right motor %50 (PWM)---------
	BSF PORTB,0
	MOVF IS,W
	CALL GECIKME
	BCF PORTB,0 
	MOVF BEK,W
	CALL GECIKME

	GOTO CYCLE

GECIKME

	MOVWF SAYAC

CYCLE2
	DECFSZ SAYAC,F
	GOTO CYCLE2 
	RETURN
END
This compiles now
 
thanks so much i willl try this code tomorrow on breadboard circuit and will say does it work or not,thanks again.
 
Programmers nightmare... Loads of goto's!

Don't you write assembler?, or use PIC's?, GOTO is essential in assembler, and particularly so on the PIC RISC devices.

GOTO is only bad practice in high level languages, which then generate loads of goto's in the assembler code anyway :D

You might try the enhanced mid-range PIC's, where you can use BRA instead of GOTO.
 
Nigel.. Not if I can help it... Look at the original code before you criticize.. There was a return at the end only all the rest were goto's I merely said it wasn't making sense... I use goto's in C, sometimes it's necessary, but bad practice...

If I bug you? let me know... You seem to take exception on all my remarks...
 
Nigel.. Not if I can help it... Look at the original code before you criticize.. There was a return at the end only all the rest were goto's I merely said it wasn't making sense... I use goto's in C, sometimes it's necessary, but bad practice...

As a Pascal programmer I'm rabidly opposed to goto's :D

I've only ever used one once, and that was in converting a third party VB programme to Delphi, and whilst by substantially rewriting the programme I'd managed to get rid of almost all of them, there was just one left I couldn't shift. As it would have required many hours work to completely rewrite the programme from scratch I left it in :eek:

However, I had to consult the Delphi helpfile to find the syntax for using Goto, as I'd never used it - or seen it used.

The point is that with high level languages goto is best avoided, but with assembler it's an absolutely essential instruction, without which you couldn't write much at all.

The assembler sample certainly wasn't great, but it's use of goto wasn't it's greatest problem, the PIC instructions BTFSS/BTFSC make the use of goto more frequent than would be otherwise.

If I bug you? let me know... You seem to take exception on all my remarks...

Not at all, I don't even take any notice of who I'm replying to - so couldn't tell you if I've replied to you previously or not. Sorry if you feel you're been picked on.
 
I once served under a managing director who was also the firms electronic / programmer, he programmed in assembler,,, so we had to. We used the H8/532 and the H8/300 RISC chips.. To debug 32k of assembled code was an arduous task, We make SLI's for the crane industry so you can't imagine the math that was required. I vowed there and then to use C for major projects... The point is, as far as he was concerned assembler was the ONLY way to achieve this. I have my own now, entirely written in C. I'm sorry! But you remind me of that director.

I have several products that have been written with machine code, it has it's place, but I don't think even you would program.. say a windows app with machine code. As for your comments on " Do you use pic's ", I have about 30 products on the market... ALL are powered by Microchip, some have two / three processors. So the answer would be yes!
 
i want to programing this pic now with pickit 2 clone but there is a problem,how can i learn Vdd value 3,3V or 5V?
 
no i want to say,can i programing with pic kit 2 and how? because i dont understand this pic yet ,pickit2 program give me an error it says no device detected and i think its about Vdd ?
 
You have it hooked up wrong Take a look at the pictures
 

Attachments

  • ICSP.jpg
    ICSP.jpg
    54.5 KB · Views: 281
  • ICSP_pinout.jpg
    ICSP_pinout.jpg
    30 KB · Views: 274
Last edited:
maybe i have got a problem with my pickit 2 clone ... imported hex but when i want to write to pic it says no device detected ...?
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top