LPC2368 - controling brightnes with potentiometer connected to the AD converter

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC2368 - controling brightnes with potentiometer connected to the AD converter

204 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by victor875 on Tue Jun 09 16:52:51 MST 2015
Hello guys. My name is Victor. I accidentally find about this forum and I need your help. I am an engineering student at 1st year. My friend and I had a task to make a running led. The speed of it is controlled by the potentiometer connected to the AD converter. We wrote the code and it is working. (the code is down below) Now, we need to make brightness control of all leds by same potentiometer connected to AD converter. It is important it is done with PWM. I know it is not that hard but we are out of time and exams are coming so if anyone could help us we would appreciate it a LOT! You can use our code and just make the necessary changes to make it work. Thanks


PCONPEQU0xE01FC0C4
AD0CREQU0xE0034000
AD0DR5EQU0xE0034024
AD0STATEQU0xE0034030
PCLKSEL0EQU0xE01FC1A8; peripheral clock selection register '0'
PINSEL3EQU0xE002C00C
PINMODE3EQU0xE002C04C
SCSEQU0xE01FC1A0; System Controls and Status Register
FIO1DIREQU0x3FFFC020; direction of pins
FIO1SETEQU0x3FFFC038; pin set
FIO1CLREQU0x3FFFC03C; pin reset
 
__main
 
; LED initialization
 
LDRR1, =SCS; fast work mode
LDRR2, [R1]
ORRR2, R2, #0x1
STRR2, [R1]
               
LDRR1, =FIO1DIR
LDR R2, [R1]
LDR R3, =0x07F80000; exit LED mode
ORR R2, R2, R3
STR R2, [R1]
        
; ADC initalization
 
LDRR1, =PCONP; ADC power/clock control bit
MOVR2, #0x1000
STRR2, [R1]

LDRR1, =AD0CR; Control register initialization
MOVR2, #0x2B0000
ORRR2, R2, #0x0420
STRR2, [R1]
LDRR1, =PCLKSEL0; clock peripheral selection
MOVR2, #0x1000000
STRR2, [R1]

LDRR1, =PINSEL3; selection of pin AD0.5
MOVR2, #0xC0000000
STRR2, [R1]

LDRR1, =PINMODE3; pull up/down register control  
MOVR2, #0xC0000000  
STRR2, [R1]

; LEDs

AGAINBLTURNOFF
LDR R3, =0x04000000; turn on LED 1
BLTURNON
BLDELAY

BLTURNOFF 
LDR R3, =0x02000000; turn on LED 2
BLTURNON
BLDELAY

BLTURNOFF
LDR R3, =0x01000000; turn on LED 3
BLTURNON
BLDELAY

BLTURNOFF 
LDR R3, =0x00800000; turn on LED 4
BLTURNON
BLDELAY

BLTURNOFF
LDR R3, =0x00400000; turn on LED 5
BLTURNON
BLDELAY

BAGAIN


TURNOFFLDR R1, =FIO1CLR
LDR R2, [R1]
LDR R3, =0x07F80000; turn off LED
ORR R2, R2, R3
STR R2, [R1]
MOVPC, LR


TURNONLDR R1, =FIO1SET 
LDR R2, [R1]
ORR R2, R2, R3; turn on LED
STR R2, [R1]
MOVPC, LR


DELAYMOV R4, #100
LDRR1, =AD0DR5; delay
LDRR2, [R1]
SUBR2, R2, #0xC0000000
ADDR2, R2, #1
MULR4, R2, R4
LOOPSUBSR4, #1
BPLLOOP
MOV PC, LR

END
Labels (1)
0 Kudos
0 Replies