Hi everybody......
I am trying to program pic16f877's ADC but there is no branch instruction in the instruction set.....
So how can I display the ADC result on the LCD in the form of numbers?????
;
include p16f877.inc;Include file for register definitions; ************************************************************; equates
count equ0x25;Manually assign register address!; ************************************************************; start at the reset vector
org 0x000; Set origin at memory address 000nop; very important - required for debuggerStart bcf STATUS,RP0 ; go to BANK 0 by setting
bcf STATUS,RP1 ; RP1:RP0 to 0 0.; Initialize contents of variables.;
movlw 0x0A; Initialize count to 10 decimal by
movwf count ; setting W and moving W -> count.;; Do the simple loop.loop decf count,F ; count = count - 1.
btfsc STATUS,Z ; Skip next instruction if Z=0.
stop goto stop ; End program.
goto loop; Continue looping!
End
Dear I wasn't mean that........ I want to say that if, for example, i have some specific value in the ADC result register and i want to use that value to display a specific number on the lcd then what will i do............for example in 89c51 with an external 8 bit ADC connected to port1 i can display its value with the help of these instructions............
Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
org 0hmov a,#0ffhmov p1,a ;make p1 as input port
again:mov r1,p1 ;move p1 value to r1mov a,#0afh
cjne r1,a,again ;if equal diplay 24 on the lcd
lcall dis24
.......................
dis24:;commands for displaying 24 on the lcd................................ret
end
If you want to display a specific something, such as a number or text string, based on something else, such as an ADC value, then you do a conditional branch as BigDog shows. I would be cautious and probably set the trigger ADC value to a range or to a greater than/less than flag (i.e. test the ADC value, if it meets that test, then set a flag bit in a flag register, then test that flag bit for the conditional branch). BigDog's example uses the zero bit of the Status register as a flag. I usually have just a "flag" register in addition that gives me 8 bits to check for various conditional branches, if needed.
@BigDog: Does your jump to "stop" (i.e., goto stop) compile?
Actually, it is not my code, I simply found the example during a quick search.
However, I see no reason why it shouldn't compile.
It basically puts the execution flow into an endless loop.
Perhaps if I find the time I'll attempt to assemble it.
@Jamal
Rather than posting additional examples, perhaps you should examine the following Gooligum tutorials in PDF form with downloadable source code:
MPLAB based IDE
**broken link removed**
**broken link removed**
MPLAB X based IDE
**broken link removed**
**broken link removed**
The tutorials are actually quite good covering both the Baseline and Midrange PIC Programming in Assembly and C using both the original MPLAB and the newer MPLAB X IDEs.
I would recommend studying the first two tutorials, they cover the majority of PIC Assembly Language required to master the topic.