sirdizel
Newbie level 3
- Joined
- May 17, 2013
- Messages
- 4
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,310
Hello, this is my first time posting on this forum and I hope this is not an issue because im asking for help in my first post here.
I want to read in 2 analogue values, both between 0 -5 volts, i want to store them in appropriate registers. The two voltages are to be compared and appropriate result to be displayed on the LED's
port A = input
port B = output( i will have LEd's connected to bit 1 and 2)
If input A is greater than B then led 1 will turn on
If input B is greater than A then led 2 will turn on
If both inputs equal then both LEDs stay off
This is the code I have so far
this is as far as i could get and im not even sure if the whole concept is incorrect or just an error in the code, any help would be much appreciated.
I want to read in 2 analogue values, both between 0 -5 volts, i want to store them in appropriate registers. The two voltages are to be compared and appropriate result to be displayed on the LED's
port A = input
port B = output( i will have LEd's connected to bit 1 and 2)
If input A is greater than B then led 1 will turn on
If input B is greater than A then led 2 will turn on
If both inputs equal then both LEDs stay off
This is the code I have so far
Code:
list p=16c74
org 0x01;
#include pic16c74.inc
#define count
call ini
Reg1 equ h'20' ;set registers h20 i 21
Reg2 equ h'21'
Movlw h'07'
Movwf cmcon ; komparator off
Clrf portb ; portb as output
bsf status, rp0 ;bank1
movlw b'00000110' ;analogue inputs Ra0 and Ra1
movwf adcon0 ; configure analogue inputs
bcf status, r ; bank 0
; ADC configure
movlw b'11000001' ;
movwf adcon0 ;a/d config
; config
bcf intcon, gie ; gie off
; conversion
conver:
; channel 0
movlw b'11000001' ; set channel 0
movwf adcon0 ; start conversion
call delay ; delay for result
bsf adcon0, go ; wait for result
btfsc adcon0,go ;check if ifnished
goto $-1
movf adres, w ; place the result in w register
movwf reg1
; channel 1
movlw b'11001001' ;set channel 1
movwf adcon0 ; start conversion
call delay ; wait for the result
bsf adcon0, go ; wait
btfsc adcon0,go ;check if ifnished
goto $-1
movf adres, w ; send result into w reg
movwf reg2
; comparision using substraction
Movlw, reg1 ;do roboczego wynik kana?u 0
Movlf, reg2 ; do roboczego wynik kana?u 1
Subwf reg1, f ; odejmuje a wynik do w
;if the result is less than 0 reg1>reg2 then C is reset
Btfss status, c ; check marker c
; negative result operations
bsf portb. 0 ;set port b.0
bcf portb. 1 ; reset portb.1
goto conver
; positive result operations
Bcf portb.0
Bsf portb.1 ; set port, reset port
goto conver
delay ; delay to get the conversion
movlw .8
movwf count
incfsz count, f
goto $-1
return
this is as far as i could get and im not even sure if the whole concept is incorrect or just an error in the code, any help would be much appreciated.
Last edited: