![]() | ![]() | ![]() |
| | |||||||
| 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) | |
| Quote:
Code: movwf Temp You then only need a 32 byte table (because bit 5 isn't part of the table), so you should 'ANDLW b'00011111' before calling the table. Another way of doing it, would be to use the full 64 byte table, but for the second half of the table have bit 7 set in the entries, then after reading the table test bit 7, and turn On or OFF accordingly - remembering to mask off bit 7 before calling the delay. The first way would be shorter, because you half the size of the table. | ||
| |
| | (permalink) |
| alamy Can you use two ' ORG ' statements like that..?? how is the assembler going to handle two ORG statements? this is the code...i have never tried it though.. Code: ;***** VARIABLE DEFINITIONS
STATUS EQU 03h ; variable used for context saving
TRISA EQU 85h ; variable used for context saving
PORTA EQU 05H
TRISB EQU 86h
PORTB EQU 06h
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
main bsf STATUS,5 ; bank 0 -----> bank 1
movlw b'00000000' ; set the port a as outputs
movwf TRISA ;
movlw b'00111111' ; set the port b as inputs
movwf TRISB
bcf STATUS,5 ; bank 1 -----> bank 0 | |
| |
| | (permalink) | |
| Quote:
That's EXACTLY the way to use ORG statements, you can use as many as you want - it just moves the current address for the assembler. If I was ading data statements I would add an ORG for that address, or add another ORG in order to place a table at the start of a 256 byte boundary. The only problem I have with the code is that 'main' is sat on the interrupt vector address, I would use a different address to free up the interrupt vector - or simply start from 0x000 if you're not using interrupts at all. Like this: Code:
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
RETFIE ; return from interrupt (just in case!)
; main now at 0x0005
main bsf STATUS,5 ; bank 0 -----> bank 1 | ||
| |
| | (permalink) |
| i did not know that..thanks for the explanation.. | |
| |
| | (permalink) | ||
| pls comment my program flow.. Quote:
Code: Read Movf PORTB,w
Subwf SP,w ; where SP define as 31 (b’11111’)
Btfss STATUS,C ; I’m not sure use this one….
Call TurnOn
Call TurnOff
TurnOn andlw b’00011111’
Call TableOn
Call DelayW
Bcf PORTA
Goto Read
TurnOff andlw b’00011111’
Call TableOff
Call DelayW
Bsf PORTA
Goto Read
TableOn Addwf pcl,f
Retlw 1
Retlw 1
Retlw 2
Retlw 1
Retlw 3
:
:
Retlw 1
TableOff Addwf pcl,f
Retlw 1
Retlw 1
Retlw 2
Retlw 1
Retlw 3
:
:
Retlw 1 Code:
Delay = 300 seconds
; Clock frequency = 4 MHz
; Actual delay = 300 seconds = 300000000 cycles
; Error = 0 %
cblock
d1
d2
d3
d4
count1
endc
DelayW movwf count1
Delay5
;299999995 cycles
movlw 0x54
movwf d1
movlw 0xA1
movwf d2
movlw 0xFD
movwf d3
movlw 0x02
movwf d4
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto $+2
decfsz d4, f
goto Delay_0
;5 cycles
goto $+1
goto $+1
nop
decfsz count1 ,f
goto Delay5
retlw 0x00 pls advice.. Quote:
| |||
| |
| | (permalink) | |||
| Quote:
How about this: Code: Read Movf PORTB,w
movwf TempW
Btfss TempW, 5 ; test bit 5
Call TurnOn
Btfsc TempW, 5
Call TurnOff
Goto Read The routine with GOTO then becomes: Code: Read Movf PORTB,w
movwf TempW
Btfss TempW, 5 ; test bit 5
Goto TurnOn
Goto TurnOff Quote:
| ||||
| |
| | (permalink) |
| Nigel how about my TableOn?…after test bit 5, it will go to TurnON or TurnOff, then in my TurnON subroutine, I include TableOn which start from 32 up to 63(?), but how do modified my table ?..in my TableOff, there’re only 32 bytes(am I right?) My code: Code: ;**********************************************************************
list p=16F84A ; list directive to define processor
#include <p16F84A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC
cblock
d1
d2
d3
d4
count1
endc
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;###############################################
; CIRCUIT FUNCTION
; to implement the inference engine for digital fuzzy controller to control
; the compressor action.
; single means - off, low , medium or high
;###############################################
;***** VARIABLE DEFINITIONS
STATUS EQU 03h ; variable used for context saving
TRISA EQU 85h ; variable used for context saving
PORTA EQU 05H
TRISB EQU 86h
PORTB EQU 06h
TempW EQU 1
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
main bsf STATUS,5 ; bank 0 -----> bank 1
movlw b'00000000' ; set the port a as outputs
movwf TRISA ;
movlw b'00111111' ; set the port b as inputs
movwf TRISB
bcf STATUS,5 ; bank 1 -----> bank 0
Read movf PORTB,w
movwf TempW
Btfss TempW, 5 ; test bit 5
Goto TurnOn
Goto TurnOff
TurnOn andlw b'00011111'; should i change to b'00111111', 32 or 64 bytes?
Call TableOn
Call DelayW
bcf PORTA
Goto Read
TurnOff andlw b'00011111
Call TableOff
Call DelayW
bsf PORTA
Goto Read
;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
; Delay = 300 seconds
; Clock frequency = 4 MHz
; Actual delay = 300 seconds = 300000000 cycles
; Error = 0 %
DelayW movwf count1
Delay5 ;299999995 cycles
movlw 0x54
movwf d1
movlw 0xA1
movwf d2
movlw 0xFD
movwf d3
movlw 0x02
movwf d4
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto $+2
decfsz d4, f
goto Delay_0 ;5 cycles
goto $+1
goto $+1
nop
decfsz count1 ,f
goto Delay5
retlw 0x00
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
TableOff Addwf PCL,f
Retlw 1 ;0
Retlw 1 ;1
Retlw 2 ;2
Retlw 1 ;3
Retlw 3 ;4
Retlw 1 ;5
Retlw 1 ;6
Retlw 2 ;7
Retlw 1 ;8
Retlw 3 ; 9
Retlw 1 ;10
Retlw 1 ;11
Retlw 2 ;12
Retlw 1 ;13
Retlw 3 ;14
Retlw 1 ;15
Retlw 1 ;16
Retlw 2 ;17
Retlw 1 ;18
Retlw 3 ;19
Retlw 1 ;20
Retlw 1 ;21
Retlw 2 ;22
Retlw 1 ;23
Retlw 3 ;24
Retlw 1 ;25
Retlw 1 ;26
Retlw 2 ;27
Retlw 1 ;28
Retlw 3 ;29
Retlw 1 ;30
Retlw 3 ;31
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
TableOn Addwf PCL,f
Retlw 2 ;32
Retlw 2 ;33
Retlw 2 ;34
Retlw 2 ;35
Retlw 3 ;36
Retlw 3 ;37
Retlw 2 ;38
Retlw 2 ;39
Retlw 1 ;40
Retlw 3 ;41
Retlw 3 ;42
Retlw 2 ;43
Retlw 2 ;44
Retlw 1 ;45
Retlw 3 ;46
Retlw 1 ;47
Retlw 2 ;48
Retlw 2 ;49
Retlw 1 ;50
Retlw 3 ;51
Retlw 1 ;52
Retlw 1 ;53
Retlw 2 ;54
Retlw 1 ;55
Retlw 3 ;56
Retlw 2 ;57
Retlw 2 ;58
Retlw 2 ;59
Retlw 1 ;60
Retlw 3 ;61
Retlw 1 ;62
Retlw 2 ;63
END ; directive 'end of program' Code: Clean: Deleting intermediary and output files. Clean: Done. Executing: "C:\Program Files\MPLAB IDE\MCHIP_Tools\mpasmwin.exe" /q /p16F84A "delay.asm" /l"delay.lst" /e"delay.err" Warning[205] I:\PROGRAMMING\DELAY.ASM 9 : Found directive in column 1. (cblock) Message[313] I:\PROGRAMMING\DELAY.ASM 9 : CBLOCK constants will start with a value of 0. Warning[205] I:\PROGRAMMING\DELAY.ASM 15 : Found directive in column 1. (ENDC) Message[302] I:\PROGRAMMING\DELAY.ASM 44 : Register in operand not in bank 0. Ensure that bank bits are correct. Message[302] I:\PROGRAMMING\DELAY.ASM 46 : Register in operand not in bank 0. Ensure that bank bits are correct. Error[128] I:\PROGRAMMING\DELAY.ASM 58 : Missing argument(s) Warning[209] I:\PROGRAMMING\DELAY.ASM 61 : Missing quote Error[128] I:\PROGRAMMING\DELAY.ASM 64 : Missing argument(s) Halting build on first failure as requested. BUILD FAILED: Wed Sep 29 10:58:09 2004 pls advice... thanks in advance | |
| |
| | (permalink) |
| i'm sorry the message should be like this Code: Clean: Deleting intermediary and output files. Clean: Done. Executing: "C:\Program Files\MPLAB IDE\MCHIP_Tools\mpasmwin.exe" /q /p16F84A "delay.asm" /l"delay.lst" /e"delay.err" Warning[205] I:\PROGRAMMING\DELAY.ASM 9 : Found directive in column 1. (cblock) Message[313] I:\PROGRAMMING\DELAY.ASM 9 : CBLOCK constants will start with a value of 0. Warning[205] I:\PROGRAMMING\DELAY.ASM 15 : Found directive in column 1. (ENDC) Message[302] I:\PROGRAMMING\DELAY.ASM 44 : Register in operand not in bank 0. Ensure that bank bits are correct. Message[302] I:\PROGRAMMING\DELAY.ASM 46 : Register in operand not in bank 0. Ensure that bank bits are correct. Error[128] I:\PROGRAMMING\DELAY.ASM 58 : Missing argument(s) Warning[209] I:\PROGRAMMING\DELAY.ASM 61 : Missing quote Error[128] I:\PROGRAMMING\DELAY.ASM 64 : Missing argument(s) Halting build on first failure as requested. | |
| |
| | (permalink) | ||
| Quote:
Code: ANDLW b'00011111' Quote:
Code: bsf PortA, 1 | |||
| |
| | (permalink) | |||
| Quote:
Quote:
Quote:
You can supress these errors by adding 'ERRORLEVEL -302' to the top of your code. Nigel already explained the BSF and BCF errors. | ||||
| |
| | (permalink) |
| thanks Nigel and exo...fixed.. | |
| |