Discussion in "8051 Discussion Forum" started by    Ûž TPS Ûž    Jul 3, 2008.
Tue Jul 08 2008, 08:27 pm
#11
case sensitive option? where? :-s
Tue Jul 08 2008, 09:01 pm
#12
ajay can u see upper portin of your massage as vel as all over te forum is blank
Thu Aug 27 2009, 09:52 pm
#13
Hi Ajay,

I have got this ckt diagram and code already ...




I am using this code and ckt for my reference now ... I have got IC ATtiny 2313 instead of AT90S2313 and I have heard that this code (which is meant for AT90S2313) is compatible with the former one ... but need to have little changes ... could u guide if there need to be any changes .. if so then what kind of changes ... bcoz I have been using this IC for first time and hence new to AVR devices .. please provide me a sooner reply as I have very sort time ...

Thanks,
shenoy
Sun Aug 30 2009, 03:59 pm
#14
I dont think there will be much changes, coz you are using replacable IC and it might be compatible with circuit.

can you create your won thread in AVR forum coz this is 8051 forum so will be better.
Fri Jun 10 2011, 02:16 pm
#15
Can somebody please supply the schematics for this code
Thanx
P.eterT

[quote]
codes

[code];**********************
;Including Controller Definetion File
;**********************

.include "2313def.inc"

;**********************
;Description
;**********************
;The connection details are as given in schematic
;LCD is connected to port B and sensor is connected
;to INT 0 pin of MCU

;**********************
;calculation Details (Formulae Used)
;**********************

;####For speed measurement####
;speed = 2*pi*R*3600*clk/time_count*1000*x
;R = radius of the wheel in cm (In this design R=25cm)
;time_count = value of timer counter in b/w
;two successive interrupts
;x = clock prescaler used (in this design x=1024)
;using this we have calculated the equivalent value of
;all the constants (except time_count all other parameters
;are constants)
;sh and sl are binary equivalent of this constant

.equ sh = $56
.equ sl = $49
.equ sht = $57 ;sht = sh + 1

;####For distance measurement####
;After every 100 m the registers holding distance values
;are incremented. For this we have used following formulae
; 2*pi*R*n/100 = 100
;R = radius of the wheel in cm (In this design R=25cm)
;n is the count which signifies that 100 m has been completed

.equ n = $40

;********************
;To give useful names to Registers
;********************

;####temporay registers####
.def temp=r16
.def temp1=r18
.def c1=r22 ;used for speed calculation and for display purpose
.def c2=r4 ;used for speed calculation and for display purpose
.def d1=r5 ;used for speed calculation and for display purpose
.def d2=r6 ;used for speed calculation and for display purpose
.def status=r7 ;holds the value of status register in case of interrupt

;####Registers used for timing####
.def count_1=r17 ;
.def time_1=r1
.def time_0=r2

;####Registers used for speed measurement####
.def sdigit_01=r19
.def sdigit_1=r20 ;holds the binary value of speed

;####Registers used for Distance measurement####
.def ddigit_01=r8 ;Holds binary value of distance (0.0 to 9.9)
.def ddigit_1=r9 ;Holds binary value of distance (10.0 to 999.9)
.def ddigit_10=r10 ;Holds binary value of distance (1000.0 to 99999.9)
.def dist_count=r13

;####Registers used for LCD display####
.def lcd_cmd=r21
.def lcd_dat=r23
.def count=r3

;####Registers used for delays####
.def low_del=r24
.def hi_del=r25

;####Registers used for EEPROM####
.def eep_reg=r11
.def eep_addr=r12

;r14r15

;*******************
;Code Segment
;*******************

.cseg

.org 0
rjmp RESET

.org INT0addr
rjmp IntV0

reti
reti
reti
reti

.org OVF0addr
rjmp TimerV0

reti
reti
reti
reti

.org $000b

;*******************
;Reset interrupt subroutine
;to be executed on Reset interrupt
;*******************

RESET:

;####Initializing Stack Pointer####

ldi temp,RAMEND
out SPL, temp

;####Initializing I/O Ports####

ldi temp, 0b11111111 ;configure PORT B for all outputs
out DDRB, temp
ldi temp,0
out DDRD,temp
ldi temp,$ff
out PORTD,temp ;configure PORT D for all inputs

;####Initializing INT 0 interrupt####
ldi temp,$40 ;Enabling INT 0 interrupt
out GIMSK,temp
ldi temp,$03 ;Interrupt on rising edge
out MCUCR,temp

;####Intializing timing process####
ldi temp,$02
out TIMSK,temp ;Enabling timer overflow interrupt
ldi temp,$05
out TCCR0,temp

ldi temp,$00 ;Initializing Registers
out TCNT0,temp

clr time_0
clr time_1

;####Initializing registers holding speed####
clr sdigit_1
clr sdigit_01

;####Initializing registers holding distance####
clr dist_count
clr ddigit_01
clr ddigit_1
clr ddigit_10
rcall eeprom_read

;####Initializing LCD Display####
rcall init_lcd
rcall init_lcd
rcall hi_delay

;####enabling global mask interrupt enable####
sei

;********************
;Main Part of the Program
;********************

main_loop:
rcall dist ;Subroutine to calculate Distance
rcall print_lcd ;Subroutine for LCD Display
rjmp main_loop

;********************
;INT 0 ISR
;********************

IntV0:
in status,SREG
in time_0,TCNT0
mov time_1,count_1
clr count_1
out TCNT0,count_1
inc dist_count
rcall speed ;Subroutine for speed calculation
out SREG,status
reti

;********************
;Timer overflow ISR
;********************

TimerV0:
in status,SREG
inc count_1
cpi count_1,sht
brsh timeff
out SREG,status
reti

timeff:
clr count_1
rcall time00
ret


;********************
;Calculation of speed
;********************

speed:
push d1
push d2
push c1
push c2
ldi temp1,$00
cp time_1,temp1
breq time0
speedq:
clr sdigit_1
ldi temp1,sh
mov c1,temp1
ldi temp1,sl
mov c2,temp1
rjmp speedcal

time0:
cp time_0,temp1
breq time00
rjmp speedq

time00:
clr sdigit_1
clr sdigit_01
pop d1
pop d2
pop c1
pop c2
ret

speedcal:
cp c1,time_1
brsh speed_cal
rjmp speed0
speed_cal:
cp c2,time_0
brsh speed_cal1
cp c1,time_1
breq speed0
rjmp speed_cal2
speed_cal1:
inc sdigit_1
sub c1,time_1
sub c2,time_0
rjmp speedcal

speed_cal2:
inc sdigit_1
sub c1,time_1
sub c2,time_0
dec c1
rjmp speedcal

speed0:
rjmp scal
scal:
mov d1,c1
mov d2,c2
ldi temp1,10
rjmp scal1
scal1:
cpi temp1,1
brne scal2
rjmp scal3
scal2:
dec temp1
add d2,c2
adc d1,c1
rjmp scal1
scal3:
cp d1,time_1
brsh scal4
rjmp speed1
scal4:
cp d2,time_0
brsh scal5
cp d1,time_1
breq speed1
rjmp scal6
scal5:
inc sdigit_01
sub d1,time_1
sub d2,time_0
rjmp scal3
scal6:
inc sdigit_01
sub d1,time_1
sub d2,time_0
dec d1
rjmp scal3
speed1:
pop d1
pop d2
pop c1
pop c2
ret

;********************
;Calculation of distance
;********************

dist:
ldi temp1,n
cp dist_count,temp1
brsh dist_cal
ret
dist_cal:
clr dist_count
inc ddigit_01

ldi temp,1
mov eep_addr,temp
mov eep_reg,ddigit_01
rcall eeprom_write

ldi temp1,100
cp ddigit_01,temp1
brsh dist_cal1
ret
dist_cal1:
clr ddigit_01
inc ddigit_1

ldi temp,1
mov eep_addr,temp
mov eep_reg,ddigit_01
rcall eeprom_write
ldi temp,2
mov eep_addr,temp
mov eep_reg,ddigit_1
rcall eeprom_write

ldi temp1,100
cp ddigit_1,temp1
brsh dist_cal2
ret
dist_cal2:
clr ddigit_1
inc ddigit_10

ldi temp,1 ;storing data to EEPROM
mov eep_addr,temp
mov eep_reg,ddigit_1
rcall eeprom_write
ldi temp,2
mov eep_addr,temp
mov eep_reg,ddigit_01
rcall eeprom_write
ldi temp,3
mov eep_addr,temp
mov eep_reg,ddigit_10
rcall eeprom_write

ldi temp1,100
cp ddigit_10,temp1
brsh dist_cal3
ret
dist_cal3:
clr dist_count
clr ddigit_01
clr ddigit_1
clr ddigit_10
ret


;********************
;Initializes distance registers values to
;previously stored value in EEPROM
;********************
eeprom_read:

cli
push temp
ldi temp,1
mov eep_addr, temp
rcall eep_nr
mov ddigit_01, eep_reg

ldi temp,2
mov eep_addr, temp
rcall eep_nr
mov ddigit_1, eep_reg

ldi temp,3
mov eep_addr, temp
rcall eep_nr
mov ddigit_10, eep_reg

pop temp
sei
ret

;********************
;Subroutine to read data from eeprom
;eep_addr holds the address of eeprom
;eep_reg holds the data read
;********************
eep_nr:
sbic EECR,EERE
rjmp eep_nr
read:
out EEAR, eep_addr
sbi EECR, EERE
nop
nop
in eep_reg, EEDR
ret

;********************
;Subroutine to write data to eeprom
;eep_addr holds the address of eeprom
;eep_reg holds the data to be written
;********************
eeprom_write:
sbic EECR, EEWE
rjmp eeprom_write
write:
out EEAR,eep_addr
out EEDR,eep_reg
cli
sbi EECR,EEMWE
sbi EECR,EEWE
sei
ret

;********************
;Init_Lcd: Initializes the 16 X 2 LCD module in 4 bit data
;transfer mode
;********************
init_lcd:
ldi lcd_cmd, 3
rcall lcd_low_cmd
rcall hi_delay

ldi lcd_cmd, 3
rcall lcd_low_cmd
rcall low_delay

ldi lcd_cmd, 3
rcall lcd_low_cmd
rcall low_delay


ldi lcd_cmd, $28 ; set 4-bit interface
rcall lcd_all_cmd

ldi lcd_cmd, 8 ; set DDRAM address to 00
rcall lcd_all_cmd

ldi lcd_cmd, $0c
rcall lcd_all_cmd

ldi lcd_cmd, 6
rcall lcd_all_cmd ; mode setting
ret

;********************
;Print_Lcd: Prints speed and distance on the LCD display module
;********************

print_lcd:

ldi lcd_cmd, $80
rcall lcd_all_cm
Sat Jun 11 2011, 12:38 am
#16
@ P.eterT
is the schematic was not there from where u download code
as it will difficult to draw it accurately
there is an error chances
Sun Jun 12 2011, 11:36 am
#17
the code is for AVR not 8051. Its better if you get the schematic from site u downloaded the code.
Mon Jun 13 2011, 05:53 am
#18
I opened up a Google search for Electronic Digital Speedometer with kilometer, & this was the site I opened. This code was at the start of the thread but I couldn't find a schematic to show me what the code was for or how it would look.

PeterT
Thu Jun 16 2011, 01:59 am
#20
so i see the circuit is just above your first post did you see there?? ATMega2313??

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Clydehet
Wed May 01 2024, 06:44 pm
Davidoried
Wed May 01 2024, 06:11 pm
KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am