From 6a8755800114bd34eed497c457238e9459cea8e9 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Mon, 10 Oct 2022 21:53:24 +0200 Subject: [PATCH] added pwm and dc motor --- ADC/.gitignore | 1 + ADC/src/adc.c | 4 +- ADC/src/adc.h | 4 +- DC-Motor/.cproject | 115 ++++ DC-Motor/.project | 27 + .../.settings/de.innot.avreclipse.core.prefs | 7 + .../org.eclipse.core.resources.prefs | 2 + DC-Motor/Debug/DC-Motor.map | 378 +++++++++++ DC-Motor/Debug/makefile | 86 +++ DC-Motor/Debug/objects.mk | 8 + DC-Motor/Debug/sources.mk | 23 + DC-Motor/Debug/src/dcmotor.d | 10 + DC-Motor/Debug/src/dcmotor.o | Bin 0 -> 5024 bytes DC-Motor/Debug/src/gpio.d | 8 + DC-Motor/Debug/src/gpio.o | Bin 0 -> 9992 bytes DC-Motor/Debug/src/pwm.d | 10 + DC-Motor/Debug/src/pwm.o | Bin 0 -> 4516 bytes DC-Motor/Debug/src/subdir.mk | 30 + DC-Motor/src/common_macros.h | 34 + DC-Motor/src/dcmotor.c | 76 +++ DC-Motor/src/dcmotor.h | 53 ++ DC-Motor/src/gpio.c | 328 ++++++++++ DC-Motor/src/gpio.h | 99 +++ DC-Motor/src/pwm.c | 50 ++ DC-Motor/src/pwm.h | 53 ++ DC-Motor/src/std_types.h | 40 ++ GPIOs/.gitignore | 1 + LCD/Debug/LCD.map | 612 ++++++++++++++++++ LCD/Debug/makefile | 86 +++ LCD/Debug/objects.mk | 8 + LCD/Debug/sources.mk | 23 + LCD/Debug/src/gpio.d | 8 + LCD/Debug/src/gpio.o | Bin 0 -> 9992 bytes LCD/Debug/src/lcd.d | 10 + LCD/Debug/src/lcd.o | Bin 0 -> 22908 bytes LCD/Debug/src/subdir.mk | 27 + LM 35 - Temperature Sensor/Debug/makefile | 86 +++ LM 35 - Temperature Sensor/Debug/objects.mk | 8 + LM 35 - Temperature Sensor/Debug/sources.mk | 23 + LM 35 - Temperature Sensor/Debug/src/adc.d | 0 .../Debug/src/subdir.mk | 27 + PWM/.cproject | 115 ++++ PWM/.gitignore | 1 + PWM/.project | 27 + PWM/.settings/de.innot.avreclipse.core.prefs | 7 + .../org.eclipse.core.resources.prefs | 2 + PWM/src/common_macros.h | 34 + PWM/src/gpio.c | 328 ++++++++++ PWM/src/gpio.h | 99 +++ PWM/src/pwm.c | 50 ++ PWM/src/pwm.h | 53 ++ PWM/src/std_types.h | 40 ++ 52 files changed, 3117 insertions(+), 4 deletions(-) create mode 100644 ADC/.gitignore create mode 100644 DC-Motor/.cproject create mode 100644 DC-Motor/.project create mode 100644 DC-Motor/.settings/de.innot.avreclipse.core.prefs create mode 100644 DC-Motor/.settings/org.eclipse.core.resources.prefs create mode 100644 DC-Motor/Debug/DC-Motor.map create mode 100644 DC-Motor/Debug/makefile create mode 100644 DC-Motor/Debug/objects.mk create mode 100644 DC-Motor/Debug/sources.mk create mode 100644 DC-Motor/Debug/src/dcmotor.d create mode 100644 DC-Motor/Debug/src/dcmotor.o create mode 100644 DC-Motor/Debug/src/gpio.d create mode 100644 DC-Motor/Debug/src/gpio.o create mode 100644 DC-Motor/Debug/src/pwm.d create mode 100644 DC-Motor/Debug/src/pwm.o create mode 100644 DC-Motor/Debug/src/subdir.mk create mode 100644 DC-Motor/src/common_macros.h create mode 100644 DC-Motor/src/dcmotor.c create mode 100644 DC-Motor/src/dcmotor.h create mode 100644 DC-Motor/src/gpio.c create mode 100644 DC-Motor/src/gpio.h create mode 100644 DC-Motor/src/pwm.c create mode 100644 DC-Motor/src/pwm.h create mode 100644 DC-Motor/src/std_types.h create mode 100644 GPIOs/.gitignore create mode 100644 LCD/Debug/LCD.map create mode 100644 LCD/Debug/makefile create mode 100644 LCD/Debug/objects.mk create mode 100644 LCD/Debug/sources.mk create mode 100644 LCD/Debug/src/gpio.d create mode 100644 LCD/Debug/src/gpio.o create mode 100644 LCD/Debug/src/lcd.d create mode 100644 LCD/Debug/src/lcd.o create mode 100644 LCD/Debug/src/subdir.mk create mode 100644 LM 35 - Temperature Sensor/Debug/makefile create mode 100644 LM 35 - Temperature Sensor/Debug/objects.mk create mode 100644 LM 35 - Temperature Sensor/Debug/sources.mk create mode 100644 LM 35 - Temperature Sensor/Debug/src/adc.d create mode 100644 LM 35 - Temperature Sensor/Debug/src/subdir.mk create mode 100644 PWM/.cproject create mode 100644 PWM/.gitignore create mode 100644 PWM/.project create mode 100644 PWM/.settings/de.innot.avreclipse.core.prefs create mode 100644 PWM/.settings/org.eclipse.core.resources.prefs create mode 100644 PWM/src/common_macros.h create mode 100644 PWM/src/gpio.c create mode 100644 PWM/src/gpio.h create mode 100644 PWM/src/pwm.c create mode 100644 PWM/src/pwm.h create mode 100644 PWM/src/std_types.h diff --git a/ADC/.gitignore b/ADC/.gitignore new file mode 100644 index 0000000..3df573f --- /dev/null +++ b/ADC/.gitignore @@ -0,0 +1 @@ +/Debug/ diff --git a/ADC/src/adc.c b/ADC/src/adc.c index 2fe13e3..be8a78b 100644 --- a/ADC/src/adc.c +++ b/ADC/src/adc.c @@ -21,7 +21,7 @@ /* * Description : - * Initialize the ADC: + * Initialize the ADC */ void ADC_init(const ADC_ConfigType * Config_Ptr){ @@ -56,7 +56,7 @@ void ADC_init(const ADC_ConfigType * Config_Ptr){ /* * Description : - * reads the channel from the ADC: + * reads the channel from the ADC using polling technique */ uint16 ADC_readChannel(uint8 ch_num){ diff --git a/ADC/src/adc.h b/ADC/src/adc.h index 3cff8c5..b6ae254 100644 --- a/ADC/src/adc.h +++ b/ADC/src/adc.h @@ -52,7 +52,7 @@ typedef struct{ /* * Description : - * Initialize the ADC: + * Initialize the ADC */ void ADC_init(const ADC_ConfigType * Config_Ptr); @@ -60,7 +60,7 @@ void ADC_init(const ADC_ConfigType * Config_Ptr); /* * Description : - * reads the channel from the ADC: + * reads the channel from the ADC */ uint16 ADC_readChannel(uint8 ch_num); diff --git a/DC-Motor/.cproject b/DC-Motor/.cproject new file mode 100644 index 0000000..c1f8eb4 --- /dev/null +++ b/DC-Motor/.cproject @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DC-Motor/.project b/DC-Motor/.project new file mode 100644 index 0000000..705d918 --- /dev/null +++ b/DC-Motor/.project @@ -0,0 +1,27 @@ + + + DC-Motor + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + de.innot.avreclipse.core.avrnature + + diff --git a/DC-Motor/.settings/de.innot.avreclipse.core.prefs b/DC-Motor/.settings/de.innot.avreclipse.core.prefs new file mode 100644 index 0000000..6139929 --- /dev/null +++ b/DC-Motor/.settings/de.innot.avreclipse.core.prefs @@ -0,0 +1,7 @@ +avrtarget/ClockFrequency=1000000 +avrtarget/ExtRAMSize=0 +avrtarget/ExtendedRAM=false +avrtarget/MCUType=atmega32 +avrtarget/UseEEPROM=false +avrtarget/UseExtendedRAMforHeap=true +eclipse.preferences.version=1 diff --git a/DC-Motor/.settings/org.eclipse.core.resources.prefs b/DC-Motor/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/DC-Motor/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/DC-Motor/Debug/DC-Motor.map b/DC-Motor/Debug/DC-Motor.map new file mode 100644 index 0000000..ee9d617 --- /dev/null +++ b/DC-Motor/Debug/DC-Motor.map @@ -0,0 +1,378 @@ +Archive member included because of file (symbol) + +c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr5\libgcc.a(_udivmodhi4.o) + ./src/pwm.o (__udivmodhi4) +c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr5\libgcc.a(_exit.o) + c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr5/crtm32.o (exit) + +Memory Configuration + +Name Origin Length Attributes +text 0x00000000 0x00020000 xr +data 0x00800060 0x0000ffa0 rw !x +eeprom 0x00810000 0x00010000 rw !x +fuse 0x00820000 0x00000400 rw !x +lock 0x00830000 0x00000400 rw !x +signature 0x00840000 0x00000400 rw !x +*default* 0x00000000 0xffffffff + +Linker script and memory map + +LOAD c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr5/crtm32.o +LOAD ./src/dcmotor.o +LOAD ./src/gpio.o +LOAD ./src/pwm.o +LOAD c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr5\libgcc.a +LOAD c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr5\libc.a +LOAD c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr5\libgcc.a + +.hash + *(.hash) + +.dynsym + *(.dynsym) + +.dynstr + *(.dynstr) + +.gnu.version + *(.gnu.version) + +.gnu.version_d + *(.gnu.version_d) + +.gnu.version_r + *(.gnu.version_r) + +.rel.init + *(.rel.init) + +.rela.init + *(.rela.init) + +.rel.text + *(.rel.text) + *(.rel.text.*) + *(.rel.gnu.linkonce.t*) + +.rela.text + *(.rela.text) + *(.rela.text.*) + *(.rela.gnu.linkonce.t*) + +.rel.fini + *(.rel.fini) + +.rela.fini + *(.rela.fini) + +.rel.rodata + *(.rel.rodata) + *(.rel.rodata.*) + *(.rel.gnu.linkonce.r*) + +.rela.rodata + *(.rela.rodata) + *(.rela.rodata.*) + *(.rela.gnu.linkonce.r*) + +.rel.data + *(.rel.data) + *(.rel.data.*) + *(.rel.gnu.linkonce.d*) + +.rela.data + *(.rela.data) + *(.rela.data.*) + *(.rela.gnu.linkonce.d*) + +.rel.ctors + *(.rel.ctors) + +.rela.ctors + *(.rela.ctors) + +.rel.dtors + *(.rel.dtors) + +.rela.dtors + *(.rela.dtors) + +.rel.got + *(.rel.got) + +.rela.got + *(.rela.got) + +.rel.bss + *(.rel.bss) + +.rela.bss + *(.rela.bss) + +.rel.plt + *(.rel.plt) + +.rela.plt + *(.rela.plt) + +.text 0x00000000 0x802 + *(.vectors) + .vectors 0x00000000 0x54 c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr5/crtm32.o + 0x00000000 __vectors + 0x00000000 __vector_default + *(.vectors) + *(.progmem.gcc*) + *(.progmem*) + 0x00000054 . = ALIGN (0x2) + 0x00000054 __trampolines_start = . + *(.trampolines) + .trampolines 0x00000054 0x0 linker stubs + *(.trampolines*) + 0x00000054 __trampolines_end = . + *(.jumptables) + *(.jumptables*) + *(.lowtext) + *(.lowtext*) + 0x00000054 __ctors_start = . + *(.ctors) + 0x00000054 __ctors_end = . + 0x00000054 __dtors_start = . + *(.dtors) + 0x00000054 __dtors_end = . + SORT(*)(.ctors) + SORT(*)(.dtors) + *(.init0) + .init0 0x00000054 0x0 c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr5/crtm32.o + 0x00000054 __init + *(.init0) + *(.init1) + *(.init1) + *(.init2) + .init2 0x00000054 0xc c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr5/crtm32.o + *(.init2) + *(.init3) + *(.init3) + *(.init4) + *(.init4) + *(.init5) + *(.init5) + *(.init6) + *(.init6) + *(.init7) + *(.init7) + *(.init8) + *(.init8) + *(.init9) + .init9 0x00000060 0x8 c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr5/crtm32.o + *(.init9) + *(.text) + .text 0x00000068 0x4 c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr5/crtm32.o + 0x00000068 __vector_1 + 0x00000068 __vector_12 + 0x00000068 __bad_interrupt + 0x00000068 __vector_6 + 0x00000068 __vector_3 + 0x00000068 __vector_11 + 0x00000068 __vector_13 + 0x00000068 __vector_17 + 0x00000068 __vector_19 + 0x00000068 __vector_7 + 0x00000068 __vector_5 + 0x00000068 __vector_4 + 0x00000068 __vector_9 + 0x00000068 __vector_2 + 0x00000068 __vector_15 + 0x00000068 __vector_8 + 0x00000068 __vector_14 + 0x00000068 __vector_10 + 0x00000068 __vector_16 + 0x00000068 __vector_18 + 0x00000068 __vector_20 + .text 0x0000006c 0x0 ./src/dcmotor.o + .text 0x0000006c 0x0 ./src/gpio.o + .text 0x0000006c 0x0 ./src/pwm.o + .text 0x0000006c 0x0 c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr5\libgcc.a(_udivmodhi4.o) + .text 0x0000006c 0x0 c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr5\libgcc.a(_exit.o) + 0x0000006c . = ALIGN (0x2) + *(.text.*) + .text.DcMotor_Init + 0x0000006c 0x36 ./src/dcmotor.o + 0x0000006c DcMotor_Init + .text.DcMotor_Rotate + 0x000000a2 0x48 ./src/dcmotor.o + 0x000000a2 DcMotor_Rotate + .text.GPIO_setupPinDirection + 0x000000ea 0x1d6 ./src/gpio.o + 0x000000ea GPIO_setupPinDirection + .text.GPIO_writePin + 0x000002c0 0x1d6 ./src/gpio.o + 0x000002c0 GPIO_writePin + .text.GPIO_readPin + 0x00000496 0x136 ./src/gpio.o + 0x00000496 GPIO_readPin + .text.GPIO_setupPortDirection + 0x000005cc 0x88 ./src/gpio.o + 0x000005cc GPIO_setupPortDirection + .text.GPIO_writePort + 0x00000654 0x88 ./src/gpio.o + 0x00000654 GPIO_writePort + .text.GPIO_readPort + 0x000006dc 0x8a ./src/gpio.o + 0x000006dc GPIO_readPort + .text.PWM_Timer0_Start + 0x00000766 0x70 ./src/pwm.o + 0x00000766 PWM_Timer0_Start + .text.libgcc 0x000007d6 0x28 c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr5\libgcc.a(_udivmodhi4.o) + 0x000007d6 __udivmodhi4 + .text.libgcc 0x000007fe 0x0 c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr5\libgcc.a(_exit.o) + 0x000007fe . = ALIGN (0x2) + *(.fini9) + .fini9 0x000007fe 0x0 c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr5\libgcc.a(_exit.o) + 0x000007fe exit + 0x000007fe _exit + *(.fini9) + *(.fini8) + *(.fini8) + *(.fini7) + *(.fini7) + *(.fini6) + *(.fini6) + *(.fini5) + *(.fini5) + *(.fini4) + *(.fini4) + *(.fini3) + *(.fini3) + *(.fini2) + *(.fini2) + *(.fini1) + *(.fini1) + *(.fini0) + .fini0 0x000007fe 0x4 c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr5\libgcc.a(_exit.o) + *(.fini0) + 0x00000802 _etext = . + +.data 0x00800060 0x0 load address 0x00000802 + 0x00800060 PROVIDE (__data_start, .) + *(.data) + .data 0x00800060 0x0 c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr5/crtm32.o + .data 0x00800060 0x0 ./src/dcmotor.o + .data 0x00800060 0x0 ./src/gpio.o + .data 0x00800060 0x0 ./src/pwm.o + .data 0x00800060 0x0 c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr5\libgcc.a(_udivmodhi4.o) + .data 0x00800060 0x0 c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr5\libgcc.a(_exit.o) + *(.data*) + *(.rodata) + *(.rodata*) + *(.gnu.linkonce.d*) + 0x00800060 . = ALIGN (0x2) + 0x00800060 _edata = . + 0x00800060 PROVIDE (__data_end, .) + +.bss 0x00800060 0x0 + 0x00800060 PROVIDE (__bss_start, .) + *(.bss) + .bss 0x00800060 0x0 c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr5/crtm32.o + .bss 0x00800060 0x0 ./src/dcmotor.o + .bss 0x00800060 0x0 ./src/gpio.o + .bss 0x00800060 0x0 ./src/pwm.o + .bss 0x00800060 0x0 c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr5\libgcc.a(_udivmodhi4.o) + .bss 0x00800060 0x0 c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr5\libgcc.a(_exit.o) + *(.bss*) + *(COMMON) + 0x00800060 PROVIDE (__bss_end, .) + 0x00000802 __data_load_start = LOADADDR (.data) + 0x00000802 __data_load_end = (__data_load_start + SIZEOF (.data)) + +.noinit 0x00800060 0x0 + 0x00800060 PROVIDE (__noinit_start, .) + *(.noinit*) + 0x00800060 PROVIDE (__noinit_end, .) + 0x00800060 _end = . + 0x00800060 PROVIDE (__heap_start, .) + +.eeprom 0x00810000 0x0 + *(.eeprom*) + 0x00810000 __eeprom_end = . + +.fuse + *(.fuse) + *(.lfuse) + *(.hfuse) + *(.efuse) + +.lock + *(.lock*) + +.signature + *(.signature*) + +.stab 0x00000000 0xc54 + *(.stab) + .stab 0x00000000 0x4c8 ./src/dcmotor.o + .stab 0x000004c8 0x5e8 ./src/gpio.o + 0x870 (size before relaxing) + .stab 0x00000ab0 0x1a4 ./src/pwm.o + 0x450 (size before relaxing) + +.stabstr 0x00000000 0xa5b + *(.stabstr) + .stabstr 0x00000000 0xa5b ./src/dcmotor.o + +.stab.excl + *(.stab.excl) + +.stab.exclstr + *(.stab.exclstr) + +.stab.index + *(.stab.index) + +.stab.indexstr + *(.stab.indexstr) + +.comment + *(.comment) + +.debug + *(.debug) + +.line + *(.line) + +.debug_srcinfo + *(.debug_srcinfo) + +.debug_sfnames + *(.debug_sfnames) + +.debug_aranges + *(.debug_aranges) + +.debug_pubnames + *(.debug_pubnames) + +.debug_info + *(.debug_info) + *(.gnu.linkonce.wi.*) + +.debug_abbrev + *(.debug_abbrev) + +.debug_line + *(.debug_line) + +.debug_frame + *(.debug_frame) + +.debug_str + *(.debug_str) + +.debug_loc + *(.debug_loc) + +.debug_macinfo + *(.debug_macinfo) +OUTPUT(DC-Motor.elf elf32-avr) +LOAD linker stubs diff --git a/DC-Motor/Debug/makefile b/DC-Motor/Debug/makefile new file mode 100644 index 0000000..b655ed4 --- /dev/null +++ b/DC-Motor/Debug/makefile @@ -0,0 +1,86 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +-include ../makefile.init + +RM := rm -rf + +# All of the sources participating in the build are defined here +-include sources.mk +-include src/subdir.mk +-include subdir.mk +-include objects.mk + +ifneq ($(MAKECMDGOALS),clean) +ifneq ($(strip $(ASM_DEPS)),) +-include $(ASM_DEPS) +endif +ifneq ($(strip $(S_DEPS)),) +-include $(S_DEPS) +endif +ifneq ($(strip $(S_UPPER_DEPS)),) +-include $(S_UPPER_DEPS) +endif +ifneq ($(strip $(C_DEPS)),) +-include $(C_DEPS) +endif +endif + +-include ../makefile.defs + +OPTIONAL_TOOL_DEPS := \ +$(wildcard ../makefile.defs) \ +$(wildcard ../makefile.init) \ +$(wildcard ../makefile.targets) \ + + +BUILD_ARTIFACT_NAME := DC-Motor +BUILD_ARTIFACT_EXTENSION := elf +BUILD_ARTIFACT_PREFIX := +BUILD_ARTIFACT := $(BUILD_ARTIFACT_PREFIX)$(BUILD_ARTIFACT_NAME)$(if $(BUILD_ARTIFACT_EXTENSION),.$(BUILD_ARTIFACT_EXTENSION),) + +# Add inputs and outputs from these tool invocations to the build variables +LSS += \ +DC-Motor.lss \ + +SIZEDUMMY += \ +sizedummy \ + + +# All Target +all: main-build + +# Main-build Target +main-build: DC-Motor.elf secondary-outputs + +# Tool invocations +DC-Motor.elf: $(OBJS) $(USER_OBJS) makefile objects.mk $(OPTIONAL_TOOL_DEPS) + @echo 'Building target: $@' + @echo 'Invoking: AVR C Linker' + avr-gcc -Wl,-Map,DC-Motor.map -mmcu=atmega32 -o "DC-Motor.elf" $(OBJS) $(USER_OBJS) $(LIBS) + @echo 'Finished building target: $@' + @echo ' ' + +DC-Motor.lss: DC-Motor.elf makefile objects.mk $(OPTIONAL_TOOL_DEPS) + @echo 'Invoking: AVR Create Extended Listing' + -avr-objdump -h -S DC-Motor.elf >"DC-Motor.lss" + @echo 'Finished building: $@' + @echo ' ' + +sizedummy: DC-Motor.elf makefile objects.mk $(OPTIONAL_TOOL_DEPS) + @echo 'Invoking: Print Size' + -avr-size --format=avr --mcu=atmega32 DC-Motor.elf + @echo 'Finished building: $@' + @echo ' ' + +# Other Targets +clean: + -$(RM) $(ELFS)$(OBJS)$(ASM_DEPS)$(S_DEPS)$(SIZEDUMMY)$(S_UPPER_DEPS)$(LSS)$(C_DEPS) DC-Motor.elf + -@echo ' ' + +secondary-outputs: $(LSS) $(SIZEDUMMY) + +.PHONY: all clean dependents main-build + +-include ../makefile.targets diff --git a/DC-Motor/Debug/objects.mk b/DC-Motor/Debug/objects.mk new file mode 100644 index 0000000..742c2da --- /dev/null +++ b/DC-Motor/Debug/objects.mk @@ -0,0 +1,8 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +USER_OBJS := + +LIBS := + diff --git a/DC-Motor/Debug/sources.mk b/DC-Motor/Debug/sources.mk new file mode 100644 index 0000000..4ef362e --- /dev/null +++ b/DC-Motor/Debug/sources.mk @@ -0,0 +1,23 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +OBJ_SRCS := +S_SRCS := +ASM_SRCS := +C_SRCS := +S_UPPER_SRCS := +O_SRCS := +ELFS := +OBJS := +ASM_DEPS := +S_DEPS := +SIZEDUMMY := +S_UPPER_DEPS := +LSS := +C_DEPS := + +# Every subdirectory with source files must be described here +SUBDIRS := \ +src \ + diff --git a/DC-Motor/Debug/src/dcmotor.d b/DC-Motor/Debug/src/dcmotor.d new file mode 100644 index 0000000..aef7dfe --- /dev/null +++ b/DC-Motor/Debug/src/dcmotor.d @@ -0,0 +1,10 @@ +src/dcmotor.o src/dcmotor.o: ../src/dcmotor.c ../src/dcmotor.h \ + ../src/std_types.h ../src/gpio.h ../src/pwm.h + +../src/dcmotor.h: + +../src/std_types.h: + +../src/gpio.h: + +../src/pwm.h: diff --git a/DC-Motor/Debug/src/dcmotor.o b/DC-Motor/Debug/src/dcmotor.o new file mode 100644 index 0000000000000000000000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GD_L}X=mCe^*(O25;QG?mn2oaiHP>@?W6@I49T&g0ZcEcxoW+C!% zVmyz4%&jOFDq`F0j_h`DqJn*jlak42-0ECwcFv4ljH_#ZZsv>uXVEi3;eYNq!Uai#`YlVIz zZUvnw+$Is#l~HNBjsx}l+Tn?*G!PARB>dJSvG7~CJ{ZaD(p^YDOLR}n>kNlwhKGXD zcF;IB87zbiA6Xs>YM~!B>g`r%7I}^yc-C_(w(KEPK?1v2syGr^dE2Q_2BYm`o}TE_ zBge3;f|f{R8}GE@$}_Y%a3qbE6M+=dm?JsrN@+#Z_5Eh0i;ad$b@{yu@BR4Yr7ss( zXIA&D-iepA#nqP*G_yLA*c7^O_VU?{D>O@7qH*_9&ZS@3`K+rXh`Q9Sa?=IGvZC4h4GwyjH_fcI7Y4#+ zok2Wgmkde!XgGooUw4G9i&v0j-4}s*y#0u`A2!p>y3fPF<8@g)O4HPF7cj458Sz3B z484g*y?JjSw}XizFx~--KX1r*ThLQ%9xujA%LlNTX5yK#>A8JCT)l4W)b}S@C~JRD zCgksze?xgXnRNB~J;3H&MIhdT81H6&dS^=a)Ya?R#7E%j^$NbzoYv+;S0ruyvT8o& z%2R%~h<(~k*M3lJ5K}2#kZ#A;j8Ez@UE4v#e`}4Oy?1%uOd;f{B75gx+xfhDs(SzPpYu*p@^h*=Q zlqPB4r#H(MNYO`s;6iH>rh|m`9bwJEmJ@>{0@_x541R<#ZBR5imj;u%{fI+n>V9UY O>uET2{RXk;sr?Q7%AP0y literal 0 HcmV?d00001 diff --git a/DC-Motor/Debug/src/gpio.d b/DC-Motor/Debug/src/gpio.d new file mode 100644 index 0000000..d0d14bb --- /dev/null +++ b/DC-Motor/Debug/src/gpio.d @@ -0,0 +1,8 @@ +src/gpio.o src/gpio.o: ../src/gpio.c ../src/gpio.h ../src/std_types.h \ + ../src/common_macros.h + +../src/gpio.h: + +../src/std_types.h: + +../src/common_macros.h: diff --git a/DC-Motor/Debug/src/gpio.o b/DC-Motor/Debug/src/gpio.o new file mode 100644 index 0000000000000000000000000000000000000000..c3fe136853a7d56022830678fc5c5d4fed583230 GIT binary patch literal 9992 zcmchce{h^d8OQgMv{J;j1}GHykpvm*4}wn$eoye+S>D(sf>#ROEI1+f>w@nV{HWmL zg5MN8XSO%*Qo(Bl#{}OZc)#F>1^-^~Yl162=FN41;FW^g1k1hX74jW|rHv|ctC^8@Y7;Y3K|fJ-7L!s@b)IWQ)gosr3hH(GOI6zOXVgK* z^{VLDuby=rQg1nqsB_67JWs_R9(UCvfib&Gg=MZ75yZ$`wM74Z&;c(;pqZx!(lige8{#QTVd@tLw1@3J9co$prFF5Y`Zygw50K7feL6IBnXJ&qq%dmTR_V*ipuEj{hZc<6V_? z^7qwt@M6qmbFxMFaAlbfRW=m(GsoxoFyH6-aHh}mVS&%{VWF?r&3nGj^P$E^K72v= zkSd#ZnV7fMH`m!|5I%&34=aTatAr1i3Ln-AA2w(o$ZS+?^xca3R`@W8+D=>q+h-Io z%#FAe_GFTM^Vkl}3G~2!Vri%NFn(9n^3>7-yRVfKwz-gfDAk^Q{Pwtt{688-v5thC`xwIvDCYg@T|JeI#DlgQQgs?NT?RH7q| zaY0HH8WyNk{n-47mcc!i<(v$Dk<4%O0%5HPXCPczt4NP!#*c{6YYb{VY$){L8tJhN zI|o^#(F=#P9`*~eW~0Y4Yzk!ITBX;I2h%n{8VItObrFUZ!)i@S`?3Hev-m zw_V%b;;$p#d~G{50(GrwL)#UbV{OTFG?`6w<&%BscB~LQ3DnUN&~Ubc=o4+5uW9!T zQG+dEcbzR{U%4?_rT~T7)zWZNGTkwdT@myL{Qf||-;hdnHsB05;8f#(bTuT?U8(+f z!f+q9YsRB;-Pu??(M?-Dqp{c=n<6tBhup$Y%!a>_80C1_<`w6Qm3o;4)j*haIk#+T zvD742sFtiY23csbi?hZ_U4B6|9AZ_IU`QNFY$tUo24NLC#^u3PKoPt z5eH}?!gQ*su(rF~{mI5z5X-UrQ^*w9M*%#xVMwsqXhI~^=p4I!Vf5LufAO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iQIL z<547=kC*!}lG;ay4$sIeFdalZM{#-Cm+T>IosXCQ31WWfpThlTZPMAOgiX5hs1T!D z;b^D|@cF1IpGZ!>fz_~l3F?c5Jk0VI)De~!QLjZIJ6EH=lDQZ4CKPM)I+lM4^%q%A zzuR@Pyc>0#<@8$}we8px>l{RV8_V~grW~MoDF^nmoc#X@^P{LALm{1`sGnjv=^SJE zTc}@R`Kzd3WBDlRQz+Jl*%(872I{#eWb-uC3s_Dz>31iRuSZRJOZux&uVHxvb(H0# zeodaN(17OnEIRJJ!0CqXRI>*?i%K^w=g-quFcocjJh5R9#vr&j$ z4uD+_u#V0F@OtR#900o<0J|JueVqefmjhsz1FWNS0PJ!A>~a9?a)9-94uD+_fL#vY z4w;RZs8oVo4uD+_fS17k8t7CIqt-dVa-9QU+KbCr$L%}hw2zxm$UfQ8`wo5>FUO>L`xGxIl452BF%cGUEn9`Rn(BPdp1pMA(_t|Kg`{ippV{RdJ1g86CG zMHD;snBWu4bRUeO(AXDIzrp+t>M;~Mc3d#!0m4(b&0S zFTk`HXQ5PpDc)twH=+(QuR-0y+>Uw`3fUq3^(^m2-Nu|neGQ7$xn3~sla*%#Yv1sh zG8-}~m0;%^*!c!_zJZ-@VCNg_Yu~`mH?Z@Kb+m8H+BatH8?*LpzVHp~d;>e*z|J?Y d^9}5LV}0!#*!c!_zOjz>jamD~oT2q${tuL7%54Au literal 0 HcmV?d00001 diff --git a/DC-Motor/Debug/src/pwm.d b/DC-Motor/Debug/src/pwm.d new file mode 100644 index 0000000..2fb97aa --- /dev/null +++ b/DC-Motor/Debug/src/pwm.d @@ -0,0 +1,10 @@ +src/pwm.o src/pwm.o: ../src/pwm.c ../src/common_macros.h ../src/gpio.h \ + ../src/std_types.h ../src/pwm.h + +../src/common_macros.h: + +../src/gpio.h: + +../src/std_types.h: + +../src/pwm.h: diff --git a/DC-Motor/Debug/src/pwm.o b/DC-Motor/Debug/src/pwm.o new file mode 100644 index 0000000000000000000000000000000000000000..b4be4b850780a96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WatJhh?waR(m33h%Acv6PU$kHg)8`wSPZNR{HL3qXG!;rI@)O+Gi5Fm!n5Lm)u8;-vs9-;jF-6!;yhhB|8> z2oU@6u4k;KNK%K(r{SNTdmhf+0x~=oUd#P+LELukCt&Xtkg1{0#d(Di!rba)Y$FKQ z0)|g*Z8!05y*@6of!V3yx2#QC^Uxf80xZXI5@V^NIfbkz6*I|nQ literal 0 HcmV?d00001 diff --git a/DC-Motor/Debug/src/subdir.mk b/DC-Motor/Debug/src/subdir.mk new file mode 100644 index 0000000..774cd3c --- /dev/null +++ b/DC-Motor/Debug/src/subdir.mk @@ -0,0 +1,30 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +# Add inputs and outputs from these tool invocations to the build variables +C_SRCS += \ +../src/dcmotor.c \ +../src/gpio.c \ +../src/pwm.c + +OBJS += \ +./src/dcmotor.o \ +./src/gpio.o \ +./src/pwm.o + +C_DEPS += \ +./src/dcmotor.d \ +./src/gpio.d \ +./src/pwm.d + + +# Each subdirectory must supply rules for building sources it contributes +src/%.o: ../src/%.c src/subdir.mk + @echo 'Building file: $<' + @echo 'Invoking: AVR Compiler' + avr-gcc -Wall -g2 -gstabs -O0 -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega32 -DF_CPU=1000000UL -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -c -o "$@" "$<" + @echo 'Finished building: $<' + @echo ' ' + + diff --git a/DC-Motor/src/common_macros.h b/DC-Motor/src/common_macros.h new file mode 100644 index 0000000..b5f8df8 --- /dev/null +++ b/DC-Motor/src/common_macros.h @@ -0,0 +1,34 @@ + /****************************************************************************** + * + * Module: Common - Macros + * File Name: Common_Macros.h + * Description: Commonly used Macros + * Author: Ibrahim Mohamed + * + *******************************************************************************/ + +#ifndef COMMON_MACROS +#define COMMON_MACROS + +/* Set a certain bit in any register */ +#define SET_BIT(REG,BIT) (REG|=(1<>num) | (REG<<(8-num)) ) + +/* Rotate left the register value with specific number of rotates */ +#define ROL(REG,num) ( REG= (REG<>(8-num)) ) + +/* Check if a specific bit is set in any register and return true if yes */ +#define BIT_IS_SET(REG,BIT) ( REG & (1< +#include "dcmotor.h" +#include "gpio.h" +#include "pwm.h" + + +/* + * Description : + * The Function responsible for setup the direction for the two motor pins through the GPIO driver. + * Stop at the DC-Motor at the beginning through the GPIO driver. + */ +void DcMotor_Init(void){ + + + /* + * set up the pins direction to be output + * + * */ + + GPIO_setupPinDirection(MOTOR_PORT_ID, MOTOR_PIN1_ID, PIN_OUTPUT); + GPIO_setupPinDirection(MOTOR_PORT_ID, MOTOR_PIN2_ID, PIN_OUTPUT); + + + /* + * set up the direction of motor to be zero + * + * */ + GPIO_writePin(MOTOR_PORT_ID, MOTOR_PIN1_ID, LOGIC_LOW); + GPIO_writePin(MOTOR_PORT_ID, MOTOR_PIN2_ID, LOGIC_LOW); + +} + + + +/* + * Description : + * set the speed and direction of the motors + */ +void DcMotor_Rotate(DcMotor_State state,uint8 speed){ + + /* + * set the state of the motor according to the configuration + * + * STOP + * MOTOR PIN 1 -> 0000 & 0001 = 0000 + * MOTOR PIN 2 -> 0000 & 00100 = 0000 .. shifted right one = 0000 + * result = 00 + * + * CW + * MOTOR PIN 1 -> 0001 & 0001 = 0001 + * MOTOR PIN 2 -> 0001 & 0010 = 0000 ..shifted right one = 0000 + * result = 10 + * + * ACW + * MOTOR PIN 1 -> 0010 & 0001 = 0000 + * MOTOR PIN 2 -> 0010 & 0010 = 0010 .. shifted right one = 0001 + * result =01 + * + * */ + + GPIO_writePin(MOTOR_PORT_ID, MOTOR_PIN1_ID, state & 0x01); + GPIO_writePin(MOTOR_PORT_ID, MOTOR_PIN2_ID, (state & 0x02) >> 1); + + PWM_Timer0_Start(speed); + +} + diff --git a/DC-Motor/src/dcmotor.h b/DC-Motor/src/dcmotor.h new file mode 100644 index 0000000..97d9949 --- /dev/null +++ b/DC-Motor/src/dcmotor.h @@ -0,0 +1,53 @@ + /****************************************************************************** + * + * Module: DC Motor + * File Name: dcmotor.h + * Description: header file for the DC Motor driver + * Author: Ibrahim Mohamed + * + *******************************************************************************/ + + +#ifndef SRC_DCMOTOR_H_ +#define SRC_DCMOTOR_H_ + +#include "std_types.h" + +/******************************************************************************* + * Configurations * + *******************************************************************************/ + +#define MOTOR_PORT_ID PORTC_ID +#define MOTOR_PIN1_ID PIN6_ID +#define MOTOR_PIN2_ID PIN0_ID + +/******************************************************************************* + * Types Declaration * + *******************************************************************************/ + +typedef enum{ + STOP, CW, ACW +} DcMotor_State; + + +/******************************************************************************* + * Functions Prototypes * + *******************************************************************************/ + +/* + * Description : + * Initialize the DC Motor driver + */ +void DcMotor_Init(void); + + + +/* + * Description : + * set the speed and direction of the motors + */ +void DcMotor_Rotate(DcMotor_State state,uint8 speed); + + + +#endif /* SRC_DCMOTOR_H_ */ diff --git a/DC-Motor/src/gpio.c b/DC-Motor/src/gpio.c new file mode 100644 index 0000000..8284730 --- /dev/null +++ b/DC-Motor/src/gpio.c @@ -0,0 +1,328 @@ + /****************************************************************************** + * + * Module: GPIO + * File Name: gpio.c + * Description: Source file for the AVR GPIO driver + * Author: Ibrahim Mohamed + * + *******************************************************************************/ + +#include "gpio.h" +#include "common_macros.h" /* To use the macros like SET_BIT */ +#include "avr/io.h" /* To use the IO Ports Registers */ + +/* + * Description : + * Setup the direction of the required pin input/output. + * If the input port number or pin number are not correct, The function will not handle the request. + */ +void GPIO_setupPinDirection(uint8 port_num, uint8 pin_num, GPIO_PinDirectionType direction) +{ + /* + * Check if the input port number is greater than NUM_OF_PINS_PER_PORT value. + * Or if the input pin number is greater than NUM_OF_PINS_PER_PORT value. + * In this case the input is not valid port/pin number + */ + if((pin_num >= NUM_OF_PINS_PER_PORT) || (port_num >= NUM_OF_PORTS)) + { + /* Do Nothing */ + } + else + { + /* Setup the pin direction as required */ + switch(port_num) + { + case PORTA_ID: + if(direction == PIN_OUTPUT) + { + SET_BIT(DDRA,pin_num); + } + else + { + CLEAR_BIT(DDRA,pin_num); + } + break; + case PORTB_ID: + if(direction == PIN_OUTPUT) + { + SET_BIT(DDRB,pin_num); + } + else + { + CLEAR_BIT(DDRB,pin_num); + } + break; + case PORTC_ID: + if(direction == PIN_OUTPUT) + { + SET_BIT(DDRC,pin_num); + } + else + { + CLEAR_BIT(DDRC,pin_num); + } + break; + case PORTD_ID: + if(direction == PIN_OUTPUT) + { + SET_BIT(DDRD,pin_num); + } + else + { + CLEAR_BIT(DDRD,pin_num); + } + break; + } + } +} + +/* + * Description : + * Write the value Logic High or Logic Low on the required pin. + * If the input port number or pin number are not correct, The function will not handle the request. + * If the pin is input, this function will enable/disable the internal pull-up resistor. + */ +void GPIO_writePin(uint8 port_num, uint8 pin_num, uint8 value) +{ + /* + * Check if the input port number is greater than NUM_OF_PINS_PER_PORT value. + * Or if the input pin number is greater than NUM_OF_PINS_PER_PORT value. + * In this case the input is not valid port/pin number + */ + if((pin_num >= NUM_OF_PINS_PER_PORT) || (port_num >= NUM_OF_PORTS)) + { + /* Do Nothing */ + } + else + { + /* Write the pin value as required */ + switch(port_num) + { + case PORTA_ID: + if(value == LOGIC_HIGH) + { + SET_BIT(PORTA,pin_num); + } + else + { + CLEAR_BIT(PORTA,pin_num); + } + break; + case PORTB_ID: + if(value == LOGIC_HIGH) + { + SET_BIT(PORTB,pin_num); + } + else + { + CLEAR_BIT(PORTB,pin_num); + } + break; + case PORTC_ID: + if(value == LOGIC_HIGH) + { + SET_BIT(PORTC,pin_num); + } + else + { + CLEAR_BIT(PORTC,pin_num); + } + break; + case PORTD_ID: + if(value == LOGIC_HIGH) + { + SET_BIT(PORTD,pin_num); + } + else + { + CLEAR_BIT(PORTD,pin_num); + } + break; + } + } +} + +/* + * Description : + * Read and return the value for the required pin, it should be Logic High or Logic Low. + * If the input port number or pin number are not correct, The function will return Logic Low. + */ +uint8 GPIO_readPin(uint8 port_num, uint8 pin_num) +{ + uint8 pin_value = LOGIC_LOW; + + /* + * Check if the input port number is greater than NUM_OF_PINS_PER_PORT value. + * Or if the input pin number is greater than NUM_OF_PINS_PER_PORT value. + * In this case the input is not valid port/pin number + */ + if((pin_num >= NUM_OF_PINS_PER_PORT) || (port_num >= NUM_OF_PORTS)) + { + /* Do Nothing */ + } + else + { + /* Read the pin value as required */ + switch(port_num) + { + case PORTA_ID: + if(BIT_IS_SET(PINA,pin_num)) + { + pin_value = LOGIC_HIGH; + } + else + { + pin_value = LOGIC_LOW; + } + break; + case PORTB_ID: + if(BIT_IS_SET(PINB,pin_num)) + { + pin_value = LOGIC_HIGH; + } + else + { + pin_value = LOGIC_LOW; + } + break; + case PORTC_ID: + if(BIT_IS_SET(PINC,pin_num)) + { + pin_value = LOGIC_HIGH; + } + else + { + pin_value = LOGIC_LOW; + } + break; + case PORTD_ID: + if(BIT_IS_SET(PIND,pin_num)) + { + pin_value = LOGIC_HIGH; + } + else + { + pin_value = LOGIC_LOW; + } + break; + } + } + + return pin_value; +} + +/* + * Description : + * Setup the direction of the required port all pins input/output. + * If the direction value is PORT_INPUT all pins in this port should be input pins. + * If the direction value is PORT_OUTPUT all pins in this port should be output pins. + * If the input port number is not correct, The function will not handle the request. + */ +void GPIO_setupPortDirection(uint8 port_num, GPIO_PortDirectionType direction) +{ + /* + * Check if the input number is greater than NUM_OF_PORTS value. + * In this case the input is not valid port number + */ + if(port_num >= NUM_OF_PORTS) + { + /* Do Nothing */ + } + else + { + /* Setup the port direction as required */ + switch(port_num) + { + case PORTA_ID: + DDRA = direction; + break; + case PORTB_ID: + DDRB = direction; + break; + case PORTC_ID: + DDRC = direction; + break; + case PORTD_ID: + DDRD = direction; + break; + } + } +} + +/* + * Description : + * Write the value on the required port. + * If any pin in the port is output pin the value will be written. + * If any pin in the port is input pin this will activate/deactivate the internal pull-up resistor. + * If the input port number is not correct, The function will not handle the request. + */ +void GPIO_writePort(uint8 port_num, uint8 value) +{ + /* + * Check if the input number is greater than NUM_OF_PORTS value. + * In this case the input is not valid port number + */ + if(port_num >= NUM_OF_PORTS) + { + /* Do Nothing */ + } + else + { + /* Write the port value as required */ + switch(port_num) + { + case PORTA_ID: + PORTA = value; + break; + case PORTB_ID: + PORTB = value; + break; + case PORTC_ID: + PORTC = value; + break; + case PORTD_ID: + PORTD = value; + break; + } + } +} + +/* + * Description : + * Read and return the value of the required port. + * If the input port number is not correct, The function will return ZERO value. + */ +uint8 GPIO_readPort(uint8 port_num) +{ + uint8 value = LOGIC_LOW; + + /* + * Check if the input number is greater than NUM_OF_PORTS value. + * In this case the input is not valid port number + */ + if(port_num >= NUM_OF_PORTS) + { + /* Do Nothing */ + } + else + { + /* Read the port value as required */ + switch(port_num) + { + case PORTA_ID: + value = PINA; + break; + case PORTB_ID: + value = PINB; + break; + case PORTC_ID: + value = PINC; + break; + case PORTD_ID: + value = PIND; + break; + } + } + + return value; +} diff --git a/DC-Motor/src/gpio.h b/DC-Motor/src/gpio.h new file mode 100644 index 0000000..b2821eb --- /dev/null +++ b/DC-Motor/src/gpio.h @@ -0,0 +1,99 @@ + /****************************************************************************** + * + * Module: GPIO + * File Name: gpio.h + * Description: Header file for the AVR GPIO driver + * Author: Ibrahim Mohamed + * + *******************************************************************************/ + +#ifndef GPIO_H_ +#define GPIO_H_ + +#include "std_types.h" + +/******************************************************************************* + * Configurations * + *******************************************************************************/ +#define NUM_OF_PORTS 4 +#define NUM_OF_PINS_PER_PORT 8 + +#define PORTA_ID 0 +#define PORTB_ID 1 +#define PORTC_ID 2 +#define PORTD_ID 3 + +#define PIN0_ID 0 +#define PIN1_ID 1 +#define PIN2_ID 2 +#define PIN3_ID 3 +#define PIN4_ID 4 +#define PIN5_ID 5 +#define PIN6_ID 6 +#define PIN7_ID 7 + +/******************************************************************************* + * Types Declaration * + *******************************************************************************/ +typedef enum +{ + PIN_INPUT,PIN_OUTPUT +}GPIO_PinDirectionType; + +typedef enum +{ + PORT_INPUT,PORT_OUTPUT=0xFF +}GPIO_PortDirectionType; + +/******************************************************************************* + * Functions Prototypes * + *******************************************************************************/ + +/* + * Description : + * Setup the direction of the required pin input/output. + * If the input port number or pin number are not correct, The function will not handle the request. + */ +void GPIO_setupPinDirection(uint8 port_num, uint8 pin_num, GPIO_PinDirectionType direction); + +/* + * Description : + * Write the value Logic High or Logic Low on the required pin. + * If the input port number or pin number are not correct, The function will not handle the request. + * If the pin is input, this function will enable/disable the internal pull-up resistor. + */ +void GPIO_writePin(uint8 port_num, uint8 pin_num, uint8 value); + +/* + * Description : + * Read and return the value for the required pin, it should be Logic High or Logic Low. + * If the input port number or pin number are not correct, The function will return Logic Low. + */ +uint8 GPIO_readPin(uint8 port_num, uint8 pin_num); + +/* + * Description : + * Setup the direction of the required port all pins input/output. + * If the direction value is PORT_INPUT all pins in this port should be input pins. + * If the direction value is PORT_OUTPUT all pins in this port should be output pins. + * If the input port number is not correct, The function will not handle the request. + */ +void GPIO_setupPortDirection(uint8 port_num, uint8 direction); + +/* + * Description : + * Write the value on the required port. + * If any pin in the port is output pin the value will be written. + * If any pin in the port is input pin this will activate/deactivate the internal pull-up resistor. + * If the input port number is not correct, The function will not handle the request. + */ +void GPIO_writePort(uint8 port_num, uint8 value); + +/* + * Description : + * Read and return the value of the required port. + * If the input port number is not correct, The function will return ZERO value. + */ +uint8 GPIO_readPort(uint8 port_num); + +#endif /* GPIO_H_ */ diff --git a/DC-Motor/src/pwm.c b/DC-Motor/src/pwm.c new file mode 100644 index 0000000..17d1f63 --- /dev/null +++ b/DC-Motor/src/pwm.c @@ -0,0 +1,50 @@ + /****************************************************************************** + * + * Module: Timer 0 PWM + * File Name: pwm.c + * Description: source file for the Timer0 PWM driver + * Author: Ibrahim Mohamed + * + *******************************************************************************/ + +#include +#include "common_macros.h" +#include "gpio.h" +#include "pwm.h" + + + +/* + * Description : + * responsible for trigger the Timer0 with the PWM Mode. + */ +void PWM_Timer0_Start(uint8 duty_cycle){ + + /* + * timer on with fast PWM Mode + * WGM00 & WGM01 -> 1 + * + * non inverting mode + * COM01 -> 1 , COM00 ->0 + * + */ + TCCR0 = (1<"LCD.lss" + @echo 'Finished building: $@' + @echo ' ' + +sizedummy: LCD.elf makefile objects.mk $(OPTIONAL_TOOL_DEPS) + @echo 'Invoking: Print Size' + -avr-size --format=avr --mcu=atmega32 LCD.elf + @echo 'Finished building: $@' + @echo ' ' + +# Other Targets +clean: + -$(RM) $(ELFS)$(OBJS)$(ASM_DEPS)$(S_DEPS)$(SIZEDUMMY)$(S_UPPER_DEPS)$(LSS)$(C_DEPS) LCD.elf + -@echo ' ' + +secondary-outputs: $(LSS) $(SIZEDUMMY) + +.PHONY: all clean dependents main-build + +-include ../makefile.targets diff --git a/LCD/Debug/objects.mk b/LCD/Debug/objects.mk new file mode 100644 index 0000000..742c2da --- /dev/null +++ b/LCD/Debug/objects.mk @@ -0,0 +1,8 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +USER_OBJS := + +LIBS := + diff --git a/LCD/Debug/sources.mk b/LCD/Debug/sources.mk new file mode 100644 index 0000000..4ef362e --- /dev/null +++ b/LCD/Debug/sources.mk @@ -0,0 +1,23 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +OBJ_SRCS := +S_SRCS := +ASM_SRCS := +C_SRCS := +S_UPPER_SRCS := +O_SRCS := +ELFS := +OBJS := +ASM_DEPS := +S_DEPS := +SIZEDUMMY := +S_UPPER_DEPS := +LSS := +C_DEPS := + +# Every subdirectory with source files must be described here +SUBDIRS := \ +src \ + diff --git a/LCD/Debug/src/gpio.d b/LCD/Debug/src/gpio.d new file mode 100644 index 0000000..d0d14bb --- /dev/null +++ b/LCD/Debug/src/gpio.d @@ -0,0 +1,8 @@ +src/gpio.o src/gpio.o: ../src/gpio.c ../src/gpio.h ../src/std_types.h \ + ../src/common_macros.h + +../src/gpio.h: + +../src/std_types.h: + +../src/common_macros.h: diff --git a/LCD/Debug/src/gpio.o b/LCD/Debug/src/gpio.o new file mode 100644 index 0000000000000000000000000000000000000000..c3fe136853a7d56022830678fc5c5d4fed583230 GIT binary patch literal 9992 zcm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;b^D|@cF1IpGZ!>fz_~l3F?c5Jk0VI)De~!QLjZIJ6EH=lDQZ4CKPM)I+lM4^%q%A zzuR@Pyc>0#<@8$}we8px>l{RV8_V~grW~MoDF^nmoc#X@^P{LALm{1`sGnjv=^SJE zTc}@R`Kzd3WBDlRQz+Jl*%(872I{#eWb-uC3s_Dz>31iRuSZRJOZux&uVHxvb(H0# zeodaN(17OnEIRJJ!0CqXRI>*?i%K^w=g-quFcocjJh5R9#vr&j$ z4uD+_u#V0F@OtR#900o<0J|JueVqefmjhsz1FWNS0PJ!A>~a9?a)9-94uD+_fL#vY z4w;RZs8oVo4uD+_fS17k8t7CIqt-dVa-9QU+KbCr$L%}hw2zxm$UfQ8`wo5>FUO>L`xGxIl452BF%cGUEn9`Rn(BPdp1pMA(_t|Kg`{ippV{RdJ1g86CG zMHD;snBWu4bRUeO(AXDIzrp+t>M;~Mc3d#!0m4(b&0S zFTk`HXQ5PpDc)twH=+(QuR-0y+>Uw`3fUq3^(^m2-Nu|neGQ7$xn3~sla*%#Yv1sh zG8-}~m0;%^*!c!_zJZ-@VCNg_Yu~`mH?Z@Kb+m8H+BatH8?*LpzVHp~d;>e*z|J?Y d^9}5LV}0!#*!c!_zOjz>jamD~oT2q${tuL7%54Au literal 0 HcmV?d00001 diff --git a/LCD/Debug/src/lcd.d b/LCD/Debug/src/lcd.d new file mode 100644 index 0000000..b456f87 --- /dev/null +++ b/LCD/Debug/src/lcd.d @@ -0,0 +1,10 @@ +src/lcd.o src/lcd.o: ../src/lcd.c ../src/common_macros.h ../src/lcd.h \ + ../src/std_types.h ../src/gpio.h + +../src/common_macros.h: + +../src/lcd.h: + +../src/std_types.h: + +../src/gpio.h: diff --git a/LCD/Debug/src/lcd.o b/LCD/Debug/src/lcd.o new file mode 100644 index 0000000000000000000000000000000000000000..46aef84a181b37b9aba22917430b7334d1a54941 GIT binary patch literal 22908 zcmeI44|G)3oyYG$q^?!5Q4zOPSwRdO%zr`*YEu{$l!Yurib@ShW&)#0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;8x@a4eKQJmn8T-|=)P58>MumyM7dgTtz_kYmnDC~l0Rq34_NZU zmi(9{KOcEt`=3QtamWVK2Y&CT7=?a5hx&FD9fvY7b)G<7MY)PYJz34&GBEq{dp~PX zsJ|NZ7R9{Bc^rj0ydFJ;qWiuCratd|UZ-4*{R^@>)`;`L%I8sF>hl{v<4|bxNz}zC z+UJ|W)Y*u-jB;gX0a^LH7|g!>#!nLp^&ddJPVs%H*P~E}*THTS-FFX|`p=-w!s)4f zK5eeXwbkTmaN1lAxyjYwGv;dOm|P7uxf*P8H8^dqhWxB@HSHre%3KXjo2wx=xf*=N zTn!zQtHCB$gH5gmr_I%n4|uMI4<=WG)8=Z(&zP&BV{$dvZwZ3>%&aNHK=EyXq|G47g+4GxB;yHrjWi}V)+K9 fZ@f%q;<(&Kqhw+%+~jp?jKjI8v>bne8=L"LM 35 - Temperature Sensor.lss" + @echo 'Finished building: $@' + @echo ' ' + +sizedummy: LM\ 35\ -\ Temperature\ Sensor.elf makefile objects.mk $(OPTIONAL_TOOL_DEPS) + @echo 'Invoking: Print Size' + -avr-size --format=avr --mcu=atmega32 LM 35 - Temperature Sensor.elf + @echo 'Finished building: $@' + @echo ' ' + +# Other Targets +clean: + -$(RM) $(ELFS)$(OBJS)$(ASM_DEPS)$(S_DEPS)$(SIZEDUMMY)$(S_UPPER_DEPS)$(LSS)$(C_DEPS) "LM 35 - Temperature Sensor.elf" + -@echo ' ' + +secondary-outputs: $(LSS) $(SIZEDUMMY) + +.PHONY: all clean dependents main-build + +-include ../makefile.targets diff --git a/LM 35 - Temperature Sensor/Debug/objects.mk b/LM 35 - Temperature Sensor/Debug/objects.mk new file mode 100644 index 0000000..742c2da --- /dev/null +++ b/LM 35 - Temperature Sensor/Debug/objects.mk @@ -0,0 +1,8 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +USER_OBJS := + +LIBS := + diff --git a/LM 35 - Temperature Sensor/Debug/sources.mk b/LM 35 - Temperature Sensor/Debug/sources.mk new file mode 100644 index 0000000..4ef362e --- /dev/null +++ b/LM 35 - Temperature Sensor/Debug/sources.mk @@ -0,0 +1,23 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +OBJ_SRCS := +S_SRCS := +ASM_SRCS := +C_SRCS := +S_UPPER_SRCS := +O_SRCS := +ELFS := +OBJS := +ASM_DEPS := +S_DEPS := +SIZEDUMMY := +S_UPPER_DEPS := +LSS := +C_DEPS := + +# Every subdirectory with source files must be described here +SUBDIRS := \ +src \ + diff --git a/LM 35 - Temperature Sensor/Debug/src/adc.d b/LM 35 - Temperature Sensor/Debug/src/adc.d new file mode 100644 index 0000000..e69de29 diff --git a/LM 35 - Temperature Sensor/Debug/src/subdir.mk b/LM 35 - Temperature Sensor/Debug/src/subdir.mk new file mode 100644 index 0000000..79f592f --- /dev/null +++ b/LM 35 - Temperature Sensor/Debug/src/subdir.mk @@ -0,0 +1,27 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +# Add inputs and outputs from these tool invocations to the build variables +C_SRCS += \ +../src/adc.c \ +../src/lm35_sensor.c + +OBJS += \ +./src/adc.o \ +./src/lm35_sensor.o + +C_DEPS += \ +./src/adc.d \ +./src/lm35_sensor.d + + +# Each subdirectory must supply rules for building sources it contributes +src/%.o: ../src/%.c src/subdir.mk + @echo 'Building file: $<' + @echo 'Invoking: AVR Compiler' + avr-gcc -Wall -g2 -gstabs -O0 -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega32 -DF_CPU=16000000UL -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -c -o "$@" "$<" + @echo 'Finished building: $<' + @echo ' ' + + diff --git a/PWM/.cproject b/PWM/.cproject new file mode 100644 index 0000000..98a0950 --- /dev/null +++ b/PWM/.cproject @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PWM/.gitignore b/PWM/.gitignore new file mode 100644 index 0000000..3df573f --- /dev/null +++ b/PWM/.gitignore @@ -0,0 +1 @@ +/Debug/ diff --git a/PWM/.project b/PWM/.project new file mode 100644 index 0000000..8f614e6 --- /dev/null +++ b/PWM/.project @@ -0,0 +1,27 @@ + + + PWM + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + de.innot.avreclipse.core.avrnature + + diff --git a/PWM/.settings/de.innot.avreclipse.core.prefs b/PWM/.settings/de.innot.avreclipse.core.prefs new file mode 100644 index 0000000..6139929 --- /dev/null +++ b/PWM/.settings/de.innot.avreclipse.core.prefs @@ -0,0 +1,7 @@ +avrtarget/ClockFrequency=1000000 +avrtarget/ExtRAMSize=0 +avrtarget/ExtendedRAM=false +avrtarget/MCUType=atmega32 +avrtarget/UseEEPROM=false +avrtarget/UseExtendedRAMforHeap=true +eclipse.preferences.version=1 diff --git a/PWM/.settings/org.eclipse.core.resources.prefs b/PWM/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/PWM/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/PWM/src/common_macros.h b/PWM/src/common_macros.h new file mode 100644 index 0000000..b5f8df8 --- /dev/null +++ b/PWM/src/common_macros.h @@ -0,0 +1,34 @@ + /****************************************************************************** + * + * Module: Common - Macros + * File Name: Common_Macros.h + * Description: Commonly used Macros + * Author: Ibrahim Mohamed + * + *******************************************************************************/ + +#ifndef COMMON_MACROS +#define COMMON_MACROS + +/* Set a certain bit in any register */ +#define SET_BIT(REG,BIT) (REG|=(1<>num) | (REG<<(8-num)) ) + +/* Rotate left the register value with specific number of rotates */ +#define ROL(REG,num) ( REG= (REG<>(8-num)) ) + +/* Check if a specific bit is set in any register and return true if yes */ +#define BIT_IS_SET(REG,BIT) ( REG & (1<= NUM_OF_PINS_PER_PORT) || (port_num >= NUM_OF_PORTS)) + { + /* Do Nothing */ + } + else + { + /* Setup the pin direction as required */ + switch(port_num) + { + case PORTA_ID: + if(direction == PIN_OUTPUT) + { + SET_BIT(DDRA,pin_num); + } + else + { + CLEAR_BIT(DDRA,pin_num); + } + break; + case PORTB_ID: + if(direction == PIN_OUTPUT) + { + SET_BIT(DDRB,pin_num); + } + else + { + CLEAR_BIT(DDRB,pin_num); + } + break; + case PORTC_ID: + if(direction == PIN_OUTPUT) + { + SET_BIT(DDRC,pin_num); + } + else + { + CLEAR_BIT(DDRC,pin_num); + } + break; + case PORTD_ID: + if(direction == PIN_OUTPUT) + { + SET_BIT(DDRD,pin_num); + } + else + { + CLEAR_BIT(DDRD,pin_num); + } + break; + } + } +} + +/* + * Description : + * Write the value Logic High or Logic Low on the required pin. + * If the input port number or pin number are not correct, The function will not handle the request. + * If the pin is input, this function will enable/disable the internal pull-up resistor. + */ +void GPIO_writePin(uint8 port_num, uint8 pin_num, uint8 value) +{ + /* + * Check if the input port number is greater than NUM_OF_PINS_PER_PORT value. + * Or if the input pin number is greater than NUM_OF_PINS_PER_PORT value. + * In this case the input is not valid port/pin number + */ + if((pin_num >= NUM_OF_PINS_PER_PORT) || (port_num >= NUM_OF_PORTS)) + { + /* Do Nothing */ + } + else + { + /* Write the pin value as required */ + switch(port_num) + { + case PORTA_ID: + if(value == LOGIC_HIGH) + { + SET_BIT(PORTA,pin_num); + } + else + { + CLEAR_BIT(PORTA,pin_num); + } + break; + case PORTB_ID: + if(value == LOGIC_HIGH) + { + SET_BIT(PORTB,pin_num); + } + else + { + CLEAR_BIT(PORTB,pin_num); + } + break; + case PORTC_ID: + if(value == LOGIC_HIGH) + { + SET_BIT(PORTC,pin_num); + } + else + { + CLEAR_BIT(PORTC,pin_num); + } + break; + case PORTD_ID: + if(value == LOGIC_HIGH) + { + SET_BIT(PORTD,pin_num); + } + else + { + CLEAR_BIT(PORTD,pin_num); + } + break; + } + } +} + +/* + * Description : + * Read and return the value for the required pin, it should be Logic High or Logic Low. + * If the input port number or pin number are not correct, The function will return Logic Low. + */ +uint8 GPIO_readPin(uint8 port_num, uint8 pin_num) +{ + uint8 pin_value = LOGIC_LOW; + + /* + * Check if the input port number is greater than NUM_OF_PINS_PER_PORT value. + * Or if the input pin number is greater than NUM_OF_PINS_PER_PORT value. + * In this case the input is not valid port/pin number + */ + if((pin_num >= NUM_OF_PINS_PER_PORT) || (port_num >= NUM_OF_PORTS)) + { + /* Do Nothing */ + } + else + { + /* Read the pin value as required */ + switch(port_num) + { + case PORTA_ID: + if(BIT_IS_SET(PINA,pin_num)) + { + pin_value = LOGIC_HIGH; + } + else + { + pin_value = LOGIC_LOW; + } + break; + case PORTB_ID: + if(BIT_IS_SET(PINB,pin_num)) + { + pin_value = LOGIC_HIGH; + } + else + { + pin_value = LOGIC_LOW; + } + break; + case PORTC_ID: + if(BIT_IS_SET(PINC,pin_num)) + { + pin_value = LOGIC_HIGH; + } + else + { + pin_value = LOGIC_LOW; + } + break; + case PORTD_ID: + if(BIT_IS_SET(PIND,pin_num)) + { + pin_value = LOGIC_HIGH; + } + else + { + pin_value = LOGIC_LOW; + } + break; + } + } + + return pin_value; +} + +/* + * Description : + * Setup the direction of the required port all pins input/output. + * If the direction value is PORT_INPUT all pins in this port should be input pins. + * If the direction value is PORT_OUTPUT all pins in this port should be output pins. + * If the input port number is not correct, The function will not handle the request. + */ +void GPIO_setupPortDirection(uint8 port_num, GPIO_PortDirectionType direction) +{ + /* + * Check if the input number is greater than NUM_OF_PORTS value. + * In this case the input is not valid port number + */ + if(port_num >= NUM_OF_PORTS) + { + /* Do Nothing */ + } + else + { + /* Setup the port direction as required */ + switch(port_num) + { + case PORTA_ID: + DDRA = direction; + break; + case PORTB_ID: + DDRB = direction; + break; + case PORTC_ID: + DDRC = direction; + break; + case PORTD_ID: + DDRD = direction; + break; + } + } +} + +/* + * Description : + * Write the value on the required port. + * If any pin in the port is output pin the value will be written. + * If any pin in the port is input pin this will activate/deactivate the internal pull-up resistor. + * If the input port number is not correct, The function will not handle the request. + */ +void GPIO_writePort(uint8 port_num, uint8 value) +{ + /* + * Check if the input number is greater than NUM_OF_PORTS value. + * In this case the input is not valid port number + */ + if(port_num >= NUM_OF_PORTS) + { + /* Do Nothing */ + } + else + { + /* Write the port value as required */ + switch(port_num) + { + case PORTA_ID: + PORTA = value; + break; + case PORTB_ID: + PORTB = value; + break; + case PORTC_ID: + PORTC = value; + break; + case PORTD_ID: + PORTD = value; + break; + } + } +} + +/* + * Description : + * Read and return the value of the required port. + * If the input port number is not correct, The function will return ZERO value. + */ +uint8 GPIO_readPort(uint8 port_num) +{ + uint8 value = LOGIC_LOW; + + /* + * Check if the input number is greater than NUM_OF_PORTS value. + * In this case the input is not valid port number + */ + if(port_num >= NUM_OF_PORTS) + { + /* Do Nothing */ + } + else + { + /* Read the port value as required */ + switch(port_num) + { + case PORTA_ID: + value = PINA; + break; + case PORTB_ID: + value = PINB; + break; + case PORTC_ID: + value = PINC; + break; + case PORTD_ID: + value = PIND; + break; + } + } + + return value; +} diff --git a/PWM/src/gpio.h b/PWM/src/gpio.h new file mode 100644 index 0000000..b2821eb --- /dev/null +++ b/PWM/src/gpio.h @@ -0,0 +1,99 @@ + /****************************************************************************** + * + * Module: GPIO + * File Name: gpio.h + * Description: Header file for the AVR GPIO driver + * Author: Ibrahim Mohamed + * + *******************************************************************************/ + +#ifndef GPIO_H_ +#define GPIO_H_ + +#include "std_types.h" + +/******************************************************************************* + * Configurations * + *******************************************************************************/ +#define NUM_OF_PORTS 4 +#define NUM_OF_PINS_PER_PORT 8 + +#define PORTA_ID 0 +#define PORTB_ID 1 +#define PORTC_ID 2 +#define PORTD_ID 3 + +#define PIN0_ID 0 +#define PIN1_ID 1 +#define PIN2_ID 2 +#define PIN3_ID 3 +#define PIN4_ID 4 +#define PIN5_ID 5 +#define PIN6_ID 6 +#define PIN7_ID 7 + +/******************************************************************************* + * Types Declaration * + *******************************************************************************/ +typedef enum +{ + PIN_INPUT,PIN_OUTPUT +}GPIO_PinDirectionType; + +typedef enum +{ + PORT_INPUT,PORT_OUTPUT=0xFF +}GPIO_PortDirectionType; + +/******************************************************************************* + * Functions Prototypes * + *******************************************************************************/ + +/* + * Description : + * Setup the direction of the required pin input/output. + * If the input port number or pin number are not correct, The function will not handle the request. + */ +void GPIO_setupPinDirection(uint8 port_num, uint8 pin_num, GPIO_PinDirectionType direction); + +/* + * Description : + * Write the value Logic High or Logic Low on the required pin. + * If the input port number or pin number are not correct, The function will not handle the request. + * If the pin is input, this function will enable/disable the internal pull-up resistor. + */ +void GPIO_writePin(uint8 port_num, uint8 pin_num, uint8 value); + +/* + * Description : + * Read and return the value for the required pin, it should be Logic High or Logic Low. + * If the input port number or pin number are not correct, The function will return Logic Low. + */ +uint8 GPIO_readPin(uint8 port_num, uint8 pin_num); + +/* + * Description : + * Setup the direction of the required port all pins input/output. + * If the direction value is PORT_INPUT all pins in this port should be input pins. + * If the direction value is PORT_OUTPUT all pins in this port should be output pins. + * If the input port number is not correct, The function will not handle the request. + */ +void GPIO_setupPortDirection(uint8 port_num, uint8 direction); + +/* + * Description : + * Write the value on the required port. + * If any pin in the port is output pin the value will be written. + * If any pin in the port is input pin this will activate/deactivate the internal pull-up resistor. + * If the input port number is not correct, The function will not handle the request. + */ +void GPIO_writePort(uint8 port_num, uint8 value); + +/* + * Description : + * Read and return the value of the required port. + * If the input port number is not correct, The function will return ZERO value. + */ +uint8 GPIO_readPort(uint8 port_num); + +#endif /* GPIO_H_ */ diff --git a/PWM/src/pwm.c b/PWM/src/pwm.c new file mode 100644 index 0000000..17d1f63 --- /dev/null +++ b/PWM/src/pwm.c @@ -0,0 +1,50 @@ + /****************************************************************************** + * + * Module: Timer 0 PWM + * File Name: pwm.c + * Description: source file for the Timer0 PWM driver + * Author: Ibrahim Mohamed + * + *******************************************************************************/ + +#include +#include "common_macros.h" +#include "gpio.h" +#include "pwm.h" + + + +/* + * Description : + * responsible for trigger the Timer0 with the PWM Mode. + */ +void PWM_Timer0_Start(uint8 duty_cycle){ + + /* + * timer on with fast PWM Mode + * WGM00 & WGM01 -> 1 + * + * non inverting mode + * COM01 -> 1 , COM00 ->0 + * + */ + TCCR0 = (1<