??? 04/05/11 13:03 Read: times |
#181709 - 8051(at89c51) temperature sensor HELP NEEDED!!! |
I am trying to figure out how to write a program for an 8051 micro controller(at89c51),it needs to be able to count the number of pulses coming in on a port in 1/20th second and converts these pulses to a temperature(via a lookup table) which i then need to display to an LCD .The crystal is an 11.0592mhz crystal.This is what i have so far .Can someone with the right experience please help in this matter the project has been going on quite a while and i need a professionals help.Thank you
$mod52 freqcntL equ 70h freqcntH equ 71h CALL LCD_CODE ;write Robert Perry CALL LCD_CODE2 ;write AIT - MC2 sjmp start ORG 0Bh LJMP Timer_Interrupt0 start: call Init_interrupts_Timer0 sjmp $ ;--------------------------------------------------------------------- 1Sec_Timer: start: CPL P3.5 ;correct port Call Delay ;jump to delay SJMP start ;jump back to start Delay: mov R0,#20d ;loop 20 times mov TMOD,#01h ;set up timer in 16bit mode loop: mov TH0,#3ch ;#76h? mov TL0,#0AFh ;#01h? SETB TR0 ;timer 0 "on" JNB TF0,$ ;jump bit not set-jump if timer flag is not set,keep looping if it isnt CLR TR0 ;clear timer start flag CLR TF0 ; clear timer timer finish flag DJNZ R0,loop ;decrement by 1 and jump back to loop if not 0 ,if it is 0 return ret ;-------------------------------------------------------------------------- LCD_CODE: DB0 EQU P2.0 DB1 EQU P2.1 DB2 EQU P2.2 DB3 EQU P2.3 DB4 EQU P2.4 DB5 EQU P2.5 DB6 EQU P2.6 DB7 EQU P2.7 EN EQU P3.7 ; on diagram as E???? RS EQU P3.3 RW EQU P3.6 DATA_1 EQU P2 ;??????? LCALL INIT_LCD LCALL CLEAR_LCD MOV A, #0FFH PUSH Acc MOV DPTR, #TEXT LOOP: POP Acc INC A PUSH Acc MOVC A,@A+DPTR LCALL WRITE_TEXT JNZ LOOP ret ;TEXT: DB 'ROBERT PERRY', 0 INIT_LCD: CLR RS MOV DATA_1,#38h SETB EN CLR EN LCALL WAIT_LCD CLR RS MOV DATA_1,#0Eh SETB EN CLR EN LCALL WAIT_LCD CLR RS MOV DATA_1,#06h SETB EN CLR EN LCALL WAIT_LCD RET CLEAR_LCD: CLR RS MOV DATA_1,#01h SETB EN CLR EN LCALL WAIT_LCD RET WAIT_LCD: CLR EN ;Start LCD command CLR RS ;It's a command SETB RW ;It's a read command MOV DATA_1,#0FFh ;Set all pins to FF initially SETB EN ;Clock out command to LCD MOV A,DATA_1 ;Read the return value JB ACC.7,WAIT_LCD ;If bit 7 high, LCD still busy CLR EN ;Finish the command CLR RW ;Turn off RW for future commands RET WRITE_TEXT: SETB RS MOV DATA_1,A SETB EN CLR EN LCALL WAIT_LCD RET org 100h TEXT: DB 'ROBERT PERRY',0h ;------------------------------------------------------------------------ LCD_CODE2: DB0 EQU P2.0 DB1 EQU P2.1 DB2 EQU P2.2 DB3 EQU P2.3 DB4 EQU P2.4 DB5 EQU P2.5 DB6 EQU P2.6 DB7 EQU P2.7 EN EQU P3.7 ; on diagram as E???? RS EQU P3.3 RW EQU P3.6 DATA_1 EQU P2 ;??????? LCALL INIT_LCD LCALL CLEAR_LCD MOV A, #0FFH PUSH Acc MOV DPTR, #TEXT LOOP: POP Acc INC A PUSH Acc MOVC A,@A+DPTR LCALL WRITE_TEXT JNZ LOOP sjmp $ ;TEXT: DB 'TEST SENTANCE', 0 INIT_LCD: CLR RS MOV DATA_1,#38h SETB EN CLR EN LCALL WAIT_LCD CLR RS MOV DATA_1,#0Eh SETB EN CLR EN LCALL WAIT_LCD CLR RS MOV DATA_1,#06h SETB EN CLR EN LCALL WAIT_LCD RET CLEAR_LCD: CLR RS MOV DATA_1,#01h SETB EN CLR EN LCALL WAIT_LCD RET WAIT_LCD: CLR EN ;Start LCD command CLR RS ;It's a command SETB RW ;It's a read command MOV DATA_1,#0FFh ;Set all pins to FF initially SETB EN ;Clock out command to LCD MOV A,DATA_1 ;Read the return value JB ACC.7,WAIT_LCD ;If bit 7 high, LCD still busy CLR EN ;Finish the command CLR RW ;Turn off RW for future commands RET WRITE_TEXT: SETB RS MOV DATA_1,A SETB EN CLR EN LCALL WAIT_LCD RET org 100h TEXT: DB 'AIT MC2',0h ;----------------------------------------------------------------------------- LCD_CODE3: DB0 EQU P2.0 DB1 EQU P2.1 DB2 EQU P2.2 DB3 EQU P2.3 DB4 EQU P2.4 DB5 EQU P2.5 DB6 EQU P2.6 DB7 EQU P2.7 EN EQU P3.7 ; on diagram as E???? RS EQU P3.3 RW EQU P3.6 DATA_1 EQU P2 ;??????? LCALL INIT_LCD LCALL CLEAR_LCD MOV A, #0FFH PUSH Acc MOV DPTR, #TEXT LOOP: POP Acc INC A PUSH Acc MOVC A,@A+DPTR LCALL WRITE_TEXT JNZ LOOP sjmp $ ;TEXT: DB 'TEST SENTANCE', 0 INIT_LCD: CLR RS MOV DATA_1,#38h SETB EN CLR EN LCALL WAIT_LCD CLR RS MOV DATA_1,#0Eh SETB EN CLR EN LCALL WAIT_LCD CLR RS MOV DATA_1,#06h SETB EN CLR EN LCALL WAIT_LCD RET CLEAR_LCD: CLR RS MOV DATA_1,#01h SETB EN CLR EN LCALL WAIT_LCD RET WAIT_LCD: CLR EN ;Start LCD command CLR RS ;It's a command SETB RW ;It's a read command MOV DATA_1,#0FFh ;Set all pins to FF initially SETB EN ;Clock out command to LCD MOV A,DATA_1 ;Read the return value JB ACC.7,WAIT_LCD ;If bit 7 high, LCD still busy CLR EN ;Finish the command CLR RW ;Turn off RW for future commands RET WRITE_TEXT: SETB RS MOV DATA_1,A SETB EN CLR EN LCALL WAIT_LCD RET org 100h TEXT: DB 'AIT MC2',0h ;----------------------------------------------------------------------------- HEX_TO_ASCII: ;converting 8-bit binary to ascii ;upon return r5,r1,r0 have ascii data (r5=MSB and r0=LSB) conv: mov b,#10 div ab ;divide by 10 mov r0,b ;save low digit mov b,#10 ;divide by 10 once more div ab orl a,#30h ;make 1st digit an ascii mov r5,a ;save the ascii (MSD) mov a,b orl a,#30h ;make 2nd digit an ascii mov r1,a ;save the ascii mov a,r0 orl a,#30h ;make 3rd digit an ascii mov r0,a ;save the ascii (LSD) ;-------------------------------------------------------------------------- LUT: movc A,A+@DPTR org 100 DB 0,5,6,10 mov DPTR,#100h CLR A movc A,@DPTR+A LOOP:mov DPTR,#TABLE CLR A mov A,P0 movc A,@DPTR+A mov P3,A SJMP 100 ORG 300h TABLE:DB 0,1,4,9,16,25,36,49,64,81 ORG 200 MESSAGE: DB 'This is Great!'0 mov DPTR,#MESSAGE LOOP:CLR A movc A,@DPTR+A jz FINISH call Display inc DPTR sjmp LOOP org 200 MESSAGE: DB 'This is great'0 FINISH: end ;------------------------------------------------------------------------ Timer_Interrupt0: mov TL0,76h mov TH0,01h CALL STOP_COUNTER ; is this not reset timers????? clr tr0???? CALL UPDATE_DATA CALL HEX_TO_ASCII CALL LCD_CODE3 ;WRITE FREQUENCY CODE TO DISPLAY TEMP CALL resetcounter ; ???? EndInt:reti; Init_interrupts_Timer0: mov TL0,76h mov TH0,01h mov TL1,#00h mov TH1,#00h mov TMOD,#010100016 ;Timer 0 in 16 bit mode ,timer 1 in 16 bit counter mode setb ET0 ;enable timer 0 interuppt setb EA ;master enable all interuppts setb TR0 ; start T0 setb TR1 ;start t1 RET UPDATE_DATA: mov freqcntL,TL1 mov freqcntH,TH1 RET STOP_COUNTER: CLR TR0 CLR TR1 RET end |
Topic | Author | Date |
8051(at89c51) temperature sensor HELP NEEDED!!! | 01/01/70 00:00 | |
need a professionals help | 01/01/70 00:00 |