microcontroller programming in asm

Discussion in 'Embedded Systems and Microcontrollers' started by priya_rm, Jun 11, 2008.

  1. priya_rm

    Thread Starter New Member

    Jun 11, 2008
    8
    0
    hello sir,
    i want to program a microcontroller based on the following logic: i am using adc(0804) in free-running mode and interfacing it to adc .I am applying a variable voltage at pin no: 6 of adc and also made a look-up-table how the adc reads.for 1volts it reads 33h,for 2 volts 67h......I want to program my microcontroller(89s52) in the following logic, I want to see the display at port 3 of the microcontroller through a seven segment display .I have written a program code but the results are not comming properly.please track the mistakes of my code and help me to write a correct one. please help,it's urgent. i am enclosing my csetb p2.5
    setb p2.6
    intr bit p2.7
    setb intr
    adc_port equ p1
    adc_val equ 30h
    output equ p3
    org 0000h
    start: acall read_adc
    acall compare
    acall conversion
    sjmp start
    conversion: clr wr
    setb wr
    read_adc: clr rd
    mov a,adc_val
    setb rd
    ret
    compare: mov a,adc_val
    cjne a,#33h,not_33
    mov r3,#01h
    acall data_display1
    not_33: cjne a,#67h,not_67
    mov r3,#02h
    acall data_display2
    not_67: cjne a,#97h,not_97
    mov r3,#03h
    acall data_display3
    not_97: cjne a,#99h,not_99
    mov r3,#04h
    acall data_display4
    not_99: cjne a,#0ffh,not_0ff
    mov r3,#05h
    not_0ff: acall data_display5
    data_display1: mov a,#33h
    mov b,#0ah
    div ab
    mov r7,b
    mov b,#0ah
    div ab
    mov r6,b
    mov r5,a
    mov p3,#92h
    acall delay
    mov p3,#0f8h
    acall delay
    data_display2: mov a,#67h
    mov b,#0ah
    div ab
    mov r7,b
    mov b,#0ah
    div ab
    mov r6,b
    mov r5,a
    mov p3,#0f9h
    acall delay
    mov p3,#0c0h
    acall delay
    mov p3,#0b0h
    acall delay
    data_display3: mov r3,#97h
    mov b,#0ah
    div ab
    mov r7,b
    mov b,#0ah
    div ab
    mov r6,b
    mov r5,a
    mov p3,#0f9h
    acall delay
    mov p3,#92h
    acall delay
    mov p3,#0f9h
    acall delay
    data_display4: mov r3,#99h
    mov b,#0ah
    div ab
    mov r7,b
    mov b,#0ah
    div ab
    mov r6,b
    mov r5,a
    mov p3,#0f9h
    acall delay
    mov p3,#92h
    acall delay
    mov p3,#0f9h
    acall delay
    data_display5: mov r3,#0ffh
    mov b,#0ah
    div ab
    mov r7,b
    mov b,#0ah
    div ab
    mov r6,b
    mov r5,a
    mov p3,#0a4h
    acall delay
    mov p3,#92h
    acall delay
    mov p3,#92h
    acall delay
    delay: mov r4,#200
    here: djnz r4,here
    ret
    end










    ode herewith
     
    Last edited: Jun 11, 2008
  2. m.majid

    Active Member

    May 28, 2008
    39
    0
    hi

    mistake 1:
    you mentioned that using adc in free running mode,
    in free runnig mode, the INT pin of ADC must be connected to WR pin of ADC, and micro should only activate the WR pin of ADC only once, in start of program.
    your code is continuously give start pulse (pulse to WR pin) to ADC

    mistake 2:
    there is semantic error in calling data_display subroutines.
    in your code after calling a data_display subroutine, all of next data_display subroutine are called,
    you should write a code after callinig each data_display to jump to the end of compare subroutine

    mistake3:
    there is not RET instruction at the end of data_display routines
     
  3. priya_rm

    Thread Starter New Member

    Jun 11, 2008
    8
    0
    thanx majid,just one more question to ask ---should i connect the intr pin of my adc with microcontroller.in my program code i have put the instruction intr pin p2.7,setb intr ,should these instructions remain as it is or should i delete them?please help ,its very urgent
     
    Last edited: Jun 11, 2008
  4. m.majid

    Active Member

    May 28, 2008
    39
    0
    u r welcome priya!
    no, only connect INTR pin of ADC to WR pin of ADC,
    eliminate codes of setting or clearing INT from you program.
    just before start, write a code to generate 1 pulse to WR.
    this pulse is for start up for ADC, after start it's no need for WR
    ...
    org 0000h
    clr wr
    acall delay
    setb wr
    acall delay
    start: acall read_adc
    ...
     
  5. priya_rm

    Thread Starter New Member

    Jun 11, 2008
    8
    0
    Hello Sir, I have connected my circuit as you said.from the program routine I hv removed the interrupt routines. I have also added the code which u provided.The problem is that though my program is simulated properly,when I connect the entire circuit it doesn't work properly.the seven segment display is unable to show the proper display.as my ADC is operating in free running mode ,so i hvn't connected the intr pin of ADC with the microcontroller. i am giving a brief description of my circuit .please point out if there is any wrong in my program or circuit connection. adc(0804) : pin no:1 cs is grounded pin no:2 rd connected to port p2.5 of microcontroller pin no3: wr connected to port p2.6 of microcontroller pin no 4: provided ttl clock externally from trainer kit pin no 5: intr ->wr pin and intr pin of ADC are shorted together and grounded and then opened. pin no6: vin+ -> provided a variable input voltage at this pointpin no:7,8,10 grouded separatelypin no:9 vref is left open ,vref->1.28vpin no:11 to pin no:18 are the data pins connected to port p3 of microcontrollerpin no:19 -> haven't connected itpin no 20: +5 volts Vcc
     
  6. priya_rm

    Thread Starter New Member

    Jun 11, 2008
    8
    0
    i am providing the program code ,please sir point out if there is still some mistake.
    setb p2.5
    setb p2.6
    adc_port equ p1
    adc_val equ 30h
    voltage_val equ r3
    output equ p3
    org 0h
    clr wr
    acall delay
    setb wr
    acall delay
    start: acall read_adc
    acall compare
    mov p1,adc_val
    sjmp start
    read_adc: clr rd
    mov a,adc_val
    nop
    nop
    setb rd
    compare: mov a,adc_val
    cjne a,#33h,not_33
    acall data_display1
    not_33: cjne a,#67h,not_67
    acall data_display2
    not_67: cjne a,#97h,not_97
    acall data_display3
    not_97: cjne a,#99h,not_99
    acall data_display4
    not_99: cjne a,#0ffh,not_0ff
    not_0ff: acall data_display5
    data_display1: mov r3,#01h
    mov a,#33h
    mov b,#0ah
    div ab
    mov r7,b
    mov b,#0ah
    div ab
    mov r6,b
    mov r5,a
    mov p3,#92h
    acall delay
    mov p3,#0f9h
    acall delay
    data_display2: mov r3,#02h
    mov a,#67h
    mov b,#0ah
    div ab
    mov r7,b
    mov b,#0ah
    div ab
    mov r6,b
    mov r5,a
    mov p3,#0f9h
    acall delay
    mov p3,#0c0h
    acall delay
    mov p3,#0b0h
    acall delay
    data_display3: mov r3,#03
    mov a,#97h
    mov b,#0ah
    div ab
    mov r7,b
    mov b,#0ah
    div ab
    mov r6,b
    mov r5,a
    mov p3,#0f9h
    acall delay
    mov p3,#92h
    acall delay
    mov p3,#0f9h
    acall delay
    data_display4: mov r3,#04h
    mov a,#99h
    mov b,#0ah
    div ab
    mov r7,b
    mov b,#0ah
    div ab
    mov r6,b
    mov r5,a
    mov p3,#0f9h
    acall delay
    mov p3,#92h
    acall delay
    mov p3,#0f9h
    acall delay
    data_display5: mov r3,#05h
    mov a,#0ffh
    mov b,#0ah
    div ab
    mov r7,b
    mov b,#0ah
    div ab
    mov r6,b
    mov r5,a
    mov p3,#0a4h
    acall delay
    mov p3,#92h
    acall delay
    mov p3,#92h
    acall delay
    delay: mov r4,#200
    here: djnz r4,here
    ret
    end
     
  7. m.majid

    Active Member

    May 28, 2008
    39
    0
    dear priya,
    sorry for delay,
    plz present the schematic diagram of your circuit,
     
  8. m.majid

    Active Member

    May 28, 2008
    39
    0
    you can write a better subroutine for display number in 7-seg,
    you may optimize code by writing one display subroutine instead of several subroutines.
     
  9. priya_rm

    Thread Starter New Member

    Jun 11, 2008
    8
    0
    thanx majid 4r ur reply,
    actually instead of using seven-segment display 4r my project ,I have decided to see the display through the led itself,so hv written a separate propgram code but here also Ifind the same difficulty .led's are not showing proper display,pls find out what are the faults in my program and pls correct it.
    setb p2.5
    setb p2.6
    adc_port equ p1
    adc_val equ 30h
    org 0h
    clr wr
    acall delay
    setb wr
    acall delay
    start: acall read_adc
    acall voltage_val
    sjmp start
    read_adc: clr rd
    mov a,adc_val
    setb rd
    ret
    voltage_val: mov r3,#01h
    acall data_display1
    mov r3,#02h
    acall data_display2
    mov r3,#03h
    acall data_display3
    mov r3,#04h
    acall data_display4
    mov r3,#05h
    acall data_display5
    ret
    data_display1: acall compare
    conversion1: mov a,#33h
    mov b,#0ah
    div ab
    mov r7,b
    mov b,#0ah
    div ab
    mov r6,b
    mov r5,a
    mov p1,r7
    acall delay
    mov p1,r6
    acall delay
    mov p1,r5
    acall delay
    ret
    data_display2: acall compare
    conversion2: mov a,#67h
    mov b,#0ah
    div ab
    mov r7,b
    mov b,#0ah
    div ab
    mov r6,b
    mov r5,a
    mov p1,r7
    acall delay
    mov p1,r6
    acall delay
    mov p1,r5
    acall delay
    ret
    data_display3: acall compare
    conversion3: mov a,#97h
    mov b,#0ah
    div ab
    mov r7,b
    mov b,#0ah
    div ab
    mov r6,b
    mov r5,a
    mov p1,r7
    acall delay
    mov p1,r6
    acall delay
    mov p1,r5
    acall delay
    ret
    data_display4: acall compare
    conversion4: mov a,#99h
    mov b,#0ah
    div ab
    mov r7,b
    mov b,#0ah
    div ab
    mov r6,b
    mov r5,a
    mov p1,r7
    acall delay
    mov p1,r6
    acall delay
    mov p1,r5
    acall delay
    ret
    data_display5: acall compare
    conversion5: mov a,#0ffh
    mov b,#0ah
    div ab
    mov r7,b
    mov b,#0ah
    div ab
    mov r6,b
    mov r5,a
    mov p1,r7
    acall delay
    mov p1,r6
    acall delay
    mov p1,r5
    acall delay
    ret
    compare: mov a,adc_val
    cjne a,#33h,not_33
    acall conversion1
    acall data_display1
    not_33: cjne a,#67h,not_67
    acall conversion2
    acall data_display2
    not_67: cjne a,#97h,not_97
    acall conversion3
    acall data_display3
    not_97: cjne a,#99h,not_99
    acall conversion4
    acall data_display4
    not_99: cjne a,#0ffh,not_0ff
    acall conversion5
    acall data_display5
    not_0ff: ret
    delay: mov r4,#200
    here: djnz r4,here
    ret
    end
     
  10. priya_rm

    Thread Starter New Member

    Jun 11, 2008
    8
    0
    please provide the pin configuration pf the sensor LM35 and LM34
     
  11. m.majid

    Active Member

    May 28, 2008
    39
    0
Loading...