Discussion in "8051 Discussion Forum" started by    Ginger92    Jun 15, 2014.
Sun Jun 15 2014, 03:52 pm
#1
Hye there, in my project i need to use 7 segment (common anode) and 2 push buttons as the input. It all starts when the 7 segment displaying '0', one input of the push button will increase it by one thus the 7 segment will shows '1', and the other push button will decrease it by one. Now all i need is the program code and i don't know where to start it. I need to use the assembly language and i'm using mcu8051ide software. Below is the picture of the circuit that i attached. Hope someone will help me in this. Thank you so much


Mon Jun 16 2014, 12:40 pm
#2
Please take a look at this:
http://www.8051projects.net/t1201-p20/project-doubts/automatic-room-light-controller-visitor-counter.htm#post_1410

We can only help.. but cannot provide you code.
Mon Jun 16 2014, 03:35 pm
#3
RB0     EQU     000H    ; Select Register Bank 0
RB1     EQU     008H    ; Select Register Bank 1  ...poke to PSW to use


DIS_A	EQU	P0.2		
DIS_B	EQU	P0.3		
DIS_C	EQU	P0.4
;DIS_D	EQU	P0.6
DIS_D	EQU	P2.2
DIS_E	EQU	P0.5
DIS_F	EQU	P0.1
DIS_G	EQU	P0.0

DIS1	EQU	P0.7
;DIS2	EQU	P2.6   
DIS2	EQU	P0.6

LIGHT	EQU	P2.7

SEN1	EQU	P1.0
SEN2	EQU	P1.1
test	EQU P1.2  
test2	EQU P1.3


        UP      BIT     0H  
        DWN     BIT     1H
        COUNT   EQU     30H
        SPEED   EQU     31H
        VALUE_1 EQU     32H
        VALUE_2 EQU     33H
        NUMB1 EQU     34H
        NUMB2 EQU     35H
		NUMB3 EQU     36H
		VISITOR EQU	37H

        STACK   EQU     50H 


;---------==========----------==========---------=========---------
;              PROCESSOR INTERRUPT AND RESET VECTORS
;---------==========----------==========---------=========---------
   
	ORG     00H    		; Reset
	JMP     MAIN
	ORG 	000BH		;Timer Interrupt0
	JMP 	REFRESH
	
;---------==========----------==========---------=========---------
;  Main routine. Program execution starts here.
;---------==========----------==========---------=========---------
MAIN:	
	MOV PSW,#RB0      	; Select register bank 0
   MOV SP,STACK
	CLR LIGHT
	CLR test2
	CLR DIS_D
	MOV VISITOR,#00H
	MOV SPEED,#00H
	MOV COUNT,#00H
	MOV VALUE_1,#15H
	MOV VALUE_2,#15H
	CLR DIS1
	CLR DIS2
	
	MOV TMOD,#01H		;enable timer0 for scanning
	MOV TL0,#00H
	MOV TH0,#0FFH
	SETB ET0
	SETB EA
	SETB TR0		;Start the Timer


		MOV VALUE_1,#00H
		MOV VALUE_2,#00H
		SETB SEN1
		SETB SEN2
UPP:	JNB SEN1,UP_COUNT
		CPL test
		JB SEN2,UPP
		
		MOV A,VISITOR			;DOWN COUNTING
		CJNE A,#00,UAPS
		CLR LIGHT
		JNB SEN2,$
		CALL DELAY
		JB SEN1,$
		CALL DELAY
		JNB SEN1,$
		CALL DELAY
		AJMP UPP			
UAPS:	DEC VISITOR	
		MOV A,VISITOR
		CJNE A,#00,UAPA
		CLR LIGHT
UAPA:	MOV R2,VISITOR
      MOV R1,#00H	
		MOV R3,#00D
      MOV R4,#00D
      MOV R5,#00D
      MOV R6,#00D
      MOV R7,#00D       
		CALL HEX2BCD
		MOV VALUE_2,R3
	   MOV VALUE_1,R4
		JNB SEN2,$
	   CALL DELAY
	   JB SEN1,$ 
	   CALL DELAY
	   JNB SEN1,$ 
	   CALL DELAY 
		AJMP UPP
	
UP_COUNT:
		SETB LIGHT
		INC VISITOR		
		MOV A,VISITOR
		CJNE A,#99,UPPS
		MOV VISITOR,#98
		JNB SEN1,$
		CALL DELAY
		JB SEN2,$
		CALL DELAY
		JNB SEN2,$
		CALL DELAY
		AJMP UPP
UPPS:	MOV R2,VISITOR
      MOV R1,#00H	
		MOV R3,#00D
      MOV R4,#00D
      MOV R5,#00D
      MOV R6,#00D
      MOV R7,#00D       
		CALL HEX2BCD
		MOV VALUE_2,R3
	   MOV VALUE_1,R4
		JNB SEN1,$
		CALL DELAY
	   JB SEN2,$
	   CALL DELAY
		JNB SEN2,$
		CALL DELAY
		AJMP UPP


;**************************************************	
HEX2BCD: 
		  MOV B,#10D
        MOV A,R2
        DIV AB
        MOV   R3,B              ;   
        MOV   B,#10             ; R7,R6,R5,R4,R3
        DIV   AB
        MOV   R4,B
        MOV   R5,A
        CJNE R1,#0H,HIGH_BYTE   ; CHECK FOR HIGH BYTE
        SJMP ENDD
 
HIGH_BYTE:
			MOV   A,#6
        	ADD   A,R3
			MOV   B,#10
			DIV   AB
        	MOV   R3,B
			ADD   A,#5
        	ADD   A,R4
			MOV   B,#10
			DIV   AB
        	MOV   R4,B
			ADD   A,#2
        	ADD   A,R5
			MOV   B,#10
			DIV   AB
        	MOV   R5,B
        	CJNE R6,#00D,ADD_IT
        	SJMP CONTINUE
ADD_IT:
        	ADD A,R6
CONTINUE:
       	 MOV R6,A
       	 DJNZ R1,HIGH_BYTE
       	 MOV B, #10D
      	 MOV A,R6
       	 DIV AB
       	 MOV R6,B
       	 MOV R7,A
ENDD:  	 RET
;***************************************************************************
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
; 	7 SEGMENT DISPLAY ROUTINE
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
DISP:
	MOV R2,SPEED
	CJNE R2,#00H,AAS1
	CLR DIS_A
	CLR DIS_B
	CLR DIS_C
	CLR DIS_D
	CLR DIS_E
	CLR DIS_F
	SETB DIS_G
	RET
AAS1:	CJNE R2,#01H,AS2
	CLR DIS_B
	CLR DIS_C
	SETB DIS_A
	SETB DIS_D
	SETB DIS_E
	SETB DIS_F
	SETB DIS_G
	RET
AS2:	CJNE R2,#02H,AS3
	CLR DIS_A
	CLR DIS_B
	CLR DIS_D
	CLR DIS_E
	CLR DIS_G
	SETB DIS_C
	SETB DIS_F
	RET
AS3:	CJNE R2,#03H,AS4
	CLR DIS_A    
	CLR DIS_B
	CLR DIS_C
	CLR DIS_D
	CLR DIS_G
	SETB DIS_E
	SETB DIS_F
	RET
AS4:	CJNE R2,#04H,AS5
	CLR DIS_B
	CLR DIS_C
	CLR DIS_F
	CLR DIS_G
	SETB DIS_A
	SETB DIS_D
	SETB DIS_E
	RET
AS5:	CJNE R2,#05H,AS6
	CLR DIS_A
	CLR DIS_C
	CLR DIS_D
	CLR DIS_F
	CLR DIS_G
	SETB  DIS_B
	SETB DIS_E
	RET
AS6:	CJNE R2,#06H,AS7
	CLR DIS_A
	CLR DIS_C
	CLR DIS_D
	CLR DIS_E
	CLR DIS_F
	CLR DIS_G
	SETB DIS_B
	RET
AS7:	CJNE R2,#07H,AS8
	CLR DIS_A
	CLR DIS_B
	CLR DIS_C
	SETB DIS_D
	SETB DIS_E
	SETB DIS_F
	SETB DIS_G
	RET
AS8:	CJNE R2,#08H,AS9
	CLR DIS_A
	CLR DIS_B
	CLR DIS_C
	CLR DIS_D
	CLR DIS_E
	CLR DIS_F
	CLR DIS_G
	RET
AS9:	CJNE R2,#09H,AS10
	CLR DIS_A
	CLR DIS_B
	CLR DIS_C
	CLR DIS_D
	CLR DIS_F
	CLR DIS_G
	SETB DIS_E
	RET
AS10:	CJNE R2,#15H,AS11		;symbol for -
	SETB DIS_A
	SETB DIS_B
	SETB DIS_C
	SETB DIS_D
	SETB DIS_E
	SETB DIS_F
	CLR DIS_G
	RET
AS11:	CJNE R2,#16H,AS12		;switch off all disp
	SETB DIS_A
	SETB DIS_B
	SETB DIS_C
	SETB DIS_D
	SETB DIS_E
	SETB DIS_F
	SETB DIS_G
	RET
AS12:	MOV SPEED,#00H
	AJMP DISP
;**********************************************************	
;		INTRRUPT ROUTINE TO REFRESH THE DISPLAY
;**********************************************************	
REFRESH:
	PUSH   PSW           ; save current registerset
   MOV    PSW,#RB1
   PUSH   ACC
	INC COUNT
	MOV R4,COUNT
QA1:	CJNE R4,#01H,QA2
	MOV SPEED,VALUE_1
	CLR DIS2
	SETB DIS1
	CALL DISP 
	AJMP DOWN   
QA2:	CJNE R4,#02H,QA3
	MOV SPEED,VALUE_2
	CLR DIS1
	SETB DIS2
	CALL DISP 
	AJMP DOWN
QA3:	MOV COUNT,#01H
	MOV R4,COUNT
	AJMP QA1
DOWN:	MOV TL0,#0FFH
	MOV TH0,#0F0H
	POP    ACC
   POP    PSW
	RETI
;**********************************************************
DELAY:
	MOV R1,#4FH
REP2:	MOV R2,#0FFH
REP1:	NOP
	DJNZ R2,REP1
	DJNZ R1,REP2
	RET
;**********************************************************	

END



the 7 segment doesnt show 0.. whats wrong T_T


[ Edited Wed Jun 18 2014, 10:17 am ]
Mon Jun 16 2014, 11:35 pm
#4
You can't use code for one project with the hardware of another, it will not work !

I assume you have to learn how to write code for the 8051, so you need to start at the beginning.
How much assembly programming do you know ?

Start by learning how the display is made to show numbers.
This code should display a '1'
org 0
        mov p0,#0f9h
wait:
        jmp wait

end


Modify it to display 0-9.
Then write a tiny program to just display 0 to 9 at one second intervals

Have a go.. post again when you can do that, or if you get stuck.

Fit 470 ohm resistors (7) between the display and the 8051 to limit current


[ Edited Tue Jun 17 2014, 01:31 am ]
Tue Jun 17 2014, 11:36 am
#5
I don't know much about the assembly.. =(
I did this so far..
org 0
mov p0,#1000000B

;wait:
;jmp wait

pattern:
jnb p2.0, inc
jnb p2.1, dec
sjmp pattern

inc:
mov p0, #1111001B
ret

dec:
mov p0, #0100100B
ret
end

Am so sorry coz i dont know much about this
Wed Jun 18 2014, 10:02 am
#6
are you following the same schematic that you've attached in first post? If yes then you need to reconsider the display assignments

DIS_A EQU P0.2
DIS_B EQU P0.3
DIS_C EQU P0.4
;DIS_D EQU P0.6
DIS_D EQU P2.2
DIS_E EQU P0.5
DIS_F EQU P0.1
DIS_G EQU P0.0
Wed Jun 18 2014, 10:17 am
#7
[Topic moved to 8051 Discussion Forum]
Thu Jun 19 2014, 05:48 am
#8


I don't know much about the assembly.. =(
I did this so far..
org 0
mov p0,#1000000B

;wait:
;jmp wait

pattern:
jnb p2.0, inc
jnb p2.1, dec
sjmp pattern

inc:
mov p0, #1111001B
ret

dec:
mov p0, #0100100B
ret
end

Am so sorry coz i dont know much about this

Ginger92


It's not what I asked you to do, but it's not a bad start.
The first problem is the switches, with your code the count would change very quickly.
mainCount equ 20h  ; create variable to hold the count


org 0
		mov p0,#40h  ;show 0
               mov mainCount,#0



;in your main loop do something like
mainloop:
	jb p2.0,checkdown   
	call incRoutine  ;not a jump.. you can't use return with jump
checkdown:
	jb p2.7,display    ;your diagram, uses pin/bit 7
	call decRoutine
display:
    call displayRoutine  ;update the display

	sjmp mainloop




;use this kind of method to do one press at a time
incRoutine:
               inc mainCount;  //do what is needed for an increment
waitInc:
               jnb p2.0, waitInc  ; wait until the button is released 
               ret



For a real circuit add pullup resisters on p2.0 and p2.7
Are you using Proteus.. which version ?
Thu Jun 19 2014, 03:06 pm
#9
So this is my cct according to your suggestion, im doing this project for simulation only, not for the real cct hardware.. Im using proteus 7.6 SP4 ..
And this is program..

mainCount equ 20h ; create variable to hold the count


org 0
mov p0,#40h ;show 0
mov mainCount,#0

mainloop:
jb p2.0,checkdown
call incRoutine ;not a jump.. you can't use return with jump
checkdown:
jb p2.7,display ;your diagram, uses pin/bit 7
call decRoutine
display:
call displayRoutine ;update the display

sjmp mainloop

;use this kind of method to do one press at a time
incRoutine:
inc mainCount; //do what is needed for an increment
waitInc:
jnb p2.0, waitInc ; wait until the button is released
ret
decRoutine:
dec mainCount
waitdec:
jnb p2.7, waitdec
ret

Did im doing it wrong?
What suppose to have in waitinc/waitdec and the maincount? tq

Thu Jun 19 2014, 03:09 pm
#10
and also the displayroutine... tq so much >.<

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

FrabSeby
Thu May 16 2024, 07:31 pm
PeterGem
Thu May 16 2024, 06:27 am
Timothywalay
Thu May 16 2024, 04:40 am
Timothypet
Wed May 15 2024, 06:14 pm
RandyBence
Wed May 15 2024, 02:00 pm
JordanDic
Wed May 15 2024, 01:55 pm
DavidDeelf
Wed May 15 2024, 11:16 am
ytaletjkca
Wed May 15 2024, 09:45 am