![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hi.. Could anyone provide some links on 18 series PIC programming? I wrote a simple LED flashing program. But it doesn't work. Pls help. Code: MOVLW 0x0F MOVWF BSR,1 ; bankselect BCF TRISD,1,1 ; rd1 output ASP BSF PORTD,1,1 ; led on CALL DELAY BCF PORTD,1,1 ; led off CALL DELAY GOTO ASP DELAY LOOP1 DECFSZ COUNT1,F,1 GOTO LOOP1 DECFSZ COUNT2,F,1 GOTO LOOP1 RETURN COUNT1 EQU 0xFF00 ; variable dec. COUNT2 EQU 0xFF01 Last edited by asp1987; 7th August 2008 at 06:50 PM. | |
| |
| | (permalink) |
| It's not complete to say the least. You need a CONFIG statement, an ORG 0x000 and include file would be nice. An END is a must for MPASM if that's what you're using. | |
| |
| | (permalink) |
| Sorry for not putting it up before. Code: LIST P=18F4620
#include <P18F4620.INC>
CONFIG OSC=XT
COUNT1 EQU 0xFF00 ; var dec.
COUNT2 EQU 0xFF01
RESET_VECTOR CODE 0x0000
goto Main
Main:
MOVLW 0x0F
MOVWF BSR,1 ; bankselect
BCF TRISD,1,1
ASP
BSF PORTD,1,1 ; led on
CALL DELAY
BCF PORTD,1,1 ; led off
CALL DELAY
GOTO ASP
DELAY
LOOP1
DECFSZ COUNT1,F,1
GOTO LOOP1
DECFSZ COUNT2,F,1
GOTO LOOP1
RETURN
END | |
| |
| | (permalink) |
| The problem could be in the circuit if not code. If you can post the schematic then we can see.
__________________ Its not the Practice that makes a man perfect. Its the Man who makes the practice perfect ----- Pradeep K. Shima ----- | |
| |
| | (permalink) |
| Also the variable RAM starts at 0x0000 Try running with the MPLAB simulator, and why the bankselect stuff? | |
| |
| | (permalink) |
| Hi thanks.. It worked. But got another problem with bcf, bsf instructions. Code: LIST P=18F4620
#include <P18F4620.INC>
CONFIG WDT=OFF
CONFIG MCLRE=ON
CONFIG DEBUG=OFF
CONFIG LVP=OFF
CONFIG OSC=XT
RESET_VECTOR CODE 0x0000
goto Main
Main:
CLRF PORTD
CLRF LATD
CLRF TRISD
MOVLW 0x00
MOVWF TRISD
ASP
MOVLW 0xFF
MOVWF PORTD ; all portd pins on
; BSF PORTD,1,1
CALL DELAY
MOVLW 0x00
MOVWF PORTD ; all portd pins off
; BCF PORTD,1,1
CALL DELAY
GOTO ASP
DELAY
LOOP1
DECFSZ 0x00,F,1 ; variables 00 and 01 as pointed out
GOTO LOOP1
DECFSZ 0x01,F,1
GOTO LOOP1
RETURN
END Could you tell me why it is so? | |
| |
| | (permalink) |
| bsf PORTD, 1 = bit set ,file D, pin one. You do not need bsf PORTD,1,1
__________________ All those who believe in psycho kinesis, raise my hand. | |
| |
| | (permalink) |
| Hi, You won't find any tutorials in 18F, but do look at and follow the 16F tutorials from people like Nigel - the ideas are still useable on the 18F. Should still stick at the 18F as they are easier to use in the long run. Don't use just numbers for your variables - plus you need to specify them before your ' main' code. Like the BSF just mentioned you do not need the extra paramenters on the DECFSZ,d1,F. ; Variable definitions ; ==================== cblock 0x010 d1 ; delay routine work files d2 endc | |
| |
| | (permalink) |
| I think that you need to understand the banking on 18F processors better. There are 16 banks of registers allowed for, 0 - 15. Each is 256 bytes. The special function registers are in the top half of bank 15 All operations that involve registers (including special function registers) will access whichever bank the bank select register (BSR) is set to. So to read or write to the file registers in bank 0 you need to set the BSR to 0 To set a bit in a port (which is a special function register) you need to set the BSR to 15 However, there is also another way of getting to some of the file registers and all of the special function registers. Each command has a flag that selects either the bank that the BSR is pointing to or the access registers. The access registers are the bottom half of bank 0 and the top half of bank 15, which is where the special function registers are. For example:- Code: addwf 0x10, f, 1 add w to 0x010 if the BSR is 0, add w to 0x110 if the BSR is 1, add w to 0x210 if the BSR is 2 etc Code: addwf 0x10, f, 0 add w to 0x010, whatever is in the BSR MPLAB makes this flag select the access registers for all commands that use the access registers, if you simply miss out the last argument (0 or 1) Where you wrote:- Code: BSF PORTD,1,1 If you had written:- Code: BSF PORTD,1 Code: MOVWF PORTD Code: MOVWF PORTD, 1 | |
| |
| | (permalink) |
| Wow.. All of u have been of very great help. Thank you. By the way the earlier project-SMS based device controller/ security system about which i had posted some doubts- it worked. Last edited by asp1987; 8th August 2008 at 06:22 PM. | |
| |
| | (permalink) |
| Hi, Is it possible to control two motors via a L293D motor driver using a PICs hardware PWM? For L293d, 01/10 means motor forward/reverse. 00/11 means slow stop/fast stop, right? So basically we need the pic pwm pins for any one motor to have complementary outputs under normal operation. How can we achieve this? Read something similar to this in 18f4620's datasheet. But couldn't understand it properly. | |
| |
| | (permalink) | |
| Quote:
__________________ ========================= Futz's Microcontrollers & Robotics ========================= Last edited by futz; 11th August 2008 at 07:15 PM. | ||
| |
| | (permalink) |
| Thank you. | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| Is there any reason to program PICs in C++? | speakerguy79 | Micro Controllers | 6 | 24th April 2008 11:28 AM |
| Program PICs without a PC! Isn't is so cool? | Funny NYPD | Micro Controllers | 22 | 19th April 2008 03:56 AM |
| How to program DIP PICs with Breadboard | Funny NYPD | Electronic Books | 9 | 15th April 2008 05:15 PM |
| Odd problem, My program kills pics | 2camjohn | Micro Controllers | 6 | 27th November 2007 06:30 PM |
| Anybody program PICs? | ab0tj | Electronic Projects Design/Ideas/Reviews | 1 | 13th April 2004 07:51 PM |