Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7950821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:22:59+00:00 2026-06-04T02:22:59+00:00

I’m currently messing around with an LPC 2378 which has an application board attached.

  • 0

I’m currently messing around with an LPC 2378 which has an application board attached. On the fan there are several components, 2 of which are a fan and a heater.

If bits 6 and 7 of port 4 are connected to the fan (motor controller), the following code will turn on the fan:

  FanOn
  STMFD r13!,{r0,r5,r14}      ; Push r0, r5 and LR
  LDR R5, =FIO4PIN            ; Address of FIO4PIN
  LDR r0, [r5]                ; Read current Port4
  ORR r0, r0, #0x80
  STR r0, [r5]                ; Output
  LDMFD r13!,{r0,r5,r14}      ; Pop r0, r5 and LR
  mov pc, r14                 ; Put link register back into PC

How can I rewrite this block of code to turn on a heater connected to bit 5 of port 4, (Setting the bit to 1 will turn it on, setting it to 0 will turn it off).

Edit after answered question:

;==============================================================================
; Turn Heater On
;==============================================================================
heaterOn
  STMFD r13!,{r0,r5,r14}      ; Push r0, r5 and LR
  LDR R5, =FIO4PIN            ; Address of FIO4PIN
  LDR r0, [r5]                ; Read current Port4
  ORR r0, r0, #0x20
  STR r0, [r5]                ; Output
  LDMFD r13!,{r0,r5,r14}      ; Pop r0, r5 and LR
  mov pc, r14                 ; Put link register back into PC     
;==============================================================================
; Turn The Heater Off
;==============================================================================        
heaterOff
  STMFD r13!,{r0,r5,r14}      ; Push r0, r5 and LR
  LDR R5, =FIO4PIN            ; Address of FIO4PIN
  LDR r0, [r5]                ; Read current Port4
  AND r0, r0, #0xDF
  STR r0, [r5]                ; Output
  LDMFD r13!,{r0,r5,r14}      ; Pop r0, r5 and LR
  mov pc, r14                 ; Put link register back into PC   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:23:00+00:00Added an answer on June 4, 2026 at 2:23 am

    As best as I understand the code, the fan is connected only to bit 7 (if bits are numerated from 0).

    The following line is responsible for turning the fan-bit on:

    ORR r0, r0, #0x80
    

    You are setting all the bits that are 1 in the “mask” to 1. Since the mask is 0x80, that is 1000 0000 in binary, it only turns on bit 7.

    Now, if you need to turn on the heater instead of the fan, and you have to set bit 5 instead of 7 (on the same port), you only need to change the mask in that line. New mask should be 0010 0000 binary, that is 0x20 in hexa, so the new code should be:

    ORR r0, r0, #0x20
    

    Also, if you want to turn the heater off at some point later, you do it by unsetting only bit 5, by anding with a mask that has 1s everywhere except on bit 5. If the mnemonic for bitwise and is BIC, the line would be:

    BIC r0, r0, 0xDF
    

    Now, I have not done any assembly in months but if I am not very mistaken, the code snippet you gave is actually a subroutine. You would call it from you main functionality with something like call to the FanOn address. And, to me, it seems that the subroutine is nice in a way that it preserves all the registers it uses, e.g. it pushes them to a stack in the first line and recovers them in the end.

    So, to re-use the code, you could just write a new subroutine for turning the heater on, and one for turning each thing off if you want, and only change the label/subroutine name for each one, e.g. FanOff, HeaterOn…

    Since all of them preserve all the registers, you can use them sequentially without worries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.