Alharad I posted you 3 of them even how to make you a board that lets you run the code.
And the link to where to down load the lessons for the LPC but before you get your hopes up you don't have the same chips
that are on the LPC board so you'll have to change the code to match your chips
Thanks! As far as writing a book I honestly don't think I'm quite qualified for that yet lol. I'm actually a beginner myself when it comes to microcontrollers, PICs and assembly language. However, I've been doing electronics for almost 20 years so I understood what the hardware did. I just needed to learn the language and figure out how to bridge the gap between hardware and software.
I dabble mainly in MIDI stuff as I am a guitarist who's been doing musical electronics for 13 years.
However, the one thing I caught onto in PIC asm is that the instructions are merely just abbreviations for an instructional sentence. Just like how I explained that "movwf" means "move contents of the w register into the file address/label that proceeds this instruction". Most if not all PIC instructions are merely just abbreviations for an instructional sentence. That made it easy to grasp PIC assembly for me.
First, we need to switch from Bank 0 to Bank 1. We do this by setting the STATUS register, which is at address 03h, bit 5 to 1.
BSF 03h,5
The BSF Means Bit Set F. The letter F means that we are going to use a memory location, or register. We are using two numbers after this instruction – 03h, which is the STATUS register address, and the number 5 which corresponds to the bit number. So, what we are saying is “Set bit 5 in address 03h to 1”.
so we set bit 5 of TRISB only to the bank 1? the other bits of TRISB are left in bank 0? That would be confusing to remember all of them!!! Am I looking at this wrong?
so we set bit 5 of TRISB only to the bank 1? the other bits of TRISB are left in bank 0? That would be confusing to remember all of them!!! Am I looking at this wrong?
No you set bit 5 of the STATUS SFR, which resides at address 0x03, to switch banks. Once you set bit 5 of STATUS, you can then address all 8 bits of TRISA, TRISB, and all other SFR's that reside in bank 1. Then you must clear bit 5 in the STATUS register to switch to bank 0 in order to address the registers which reside in bank 0.
Just use banksel and for get all that bank switching stuff
Then it's a simple
Code:
banksel TRISB ;Since this register is in bank 1,
;not default bank 0, banksel is
;used to ensure bank bits are correct.
clrf TRISB ;Clear TRISB. Sets PORTB to outputs.
banksel PORTB ;banksel used to return to bank 0,
;where PORTB is located.
movlw 0x55 ;Set PORTB value.
movwf PORTB
goto $
end ;All programs must have an end.
BTW...when you right your code, use the tab button rather than a single space. Single space does work, however the code becomes easier to manage/read when you use a tab space rather than a single space.
Also, instructions go in column 2. In your example you have them in column 1, which is the label column. The code will not assemble if instructions are in the label column. This means you must tab over first prior to typing instructions.
Code should look like this -
Code:
Whitespace banksel TRISA
movlw 0xFE
movwf TRISA
Not this -
Code:
banksel TRISA
movlw 0xFE
movwf TRISA
The "Whitespace" label was merely to illustrate that there should be white space between the page margin and the instruction unless you want to label that particular instruction line.
Here is your code corrected. Compare mine to yours and take note of all differences you see -
Code:
list p=16F648A ;define processor
include <p16F648a.inc> ;include header file
__CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_OFF & _INTOSC_OSC_NOCLKOUT
radix dec ;define radix as decimal unless otherwise noted
ORG 0
;Define RAM location
Delay1 EQU 0x20
Delay2 EQU 0x21
START
banksel TRISA ;switch to bank 1
movlw 0xFF ;Arrange Port A as output
movwf TRISA
movlw 0xFF ;Arrange Port B as output. Even though PORT B is not used, it must be defined
movwf TRISB ;as output if no pull up resistors exist on the PORT B pins
movlw 0x07
movwf CMCON ;disable on chip comparator (required instruction for this PIC if not using the comparator)
BLINK
banksel PORTA ;switch to bank 0
bsf PORTA,1 ;Turn on output to LED
call Delay_1s ;Wait
bcf PORTA,1 ;Turn off output to LED
call Delay_1s ;Wait
goto BLINK ;Loop forever
; Subroutines
Delay_1s
movlw 255 ;Pre-load delay counters with starting decriment value. Value 255 is the highest value you can
movwf Delay1 ;use on 8 bit processors. Decimal 255 can be noted as 0xFF or b'11111111'. For long delays, use
movwf Delay2 ;a nested delay loop as illustrated here.
Wait
decfsz Delay, F
goto Wait
decfsz Delay2,F
goto Wait
return
In regards to the header file, that is what the "include" instruction is for.
Also, "banksel" only needs to be used when switching from one bank to another. You don't have to use it every time you address a register...only when switching to the bank that said register resides in. If you're already in the bank that the register you're addressing resides in, using banksel to address the register becomes redundant and generates unneeded code.
Also, you cannot have labels on the same line that a "banksel" directive resides on.
1. What is radix?
2. How do i know my processor frequency? is it 4 MHZ or what not?
3. I read where you calculate your delay from your processor frequency, how do i do that?
4. I meant how to include my header file in the little box, it shows source file, header file, object file, library file and a few others. is the header file for p16f648a in my C drive?
I figured out how to get the header file thing working and source code. But when I build the program it says "Do you want this project to generate absolute or relocatable code?"