uni

University stuff
git clone git://git.margiolis.net/uni.git
Log | Files | Refs | README | LICENSE

commit 044eb359382d61bcbdbbc605fd4c7194c7ab6b4f
parent 7b8b10085a264305d59c051e4b4545fb0ac689fd
Author: Christos Margiolis <christos@margiolis.net>
Date:   Tue, 25 Jan 2022 02:03:45 +0200

basic lcd driver done

Diffstat:
Mc_embedded/schem/pic.pro | 4++--
Mc_embedded/schem/pic.sch | 404+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Mc_embedded/schem/pic.sch-bak | 368++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
Mc_embedded/schem/schem.pdf | 0
Mc_embedded/src/main.c | 150++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------
5 files changed, 571 insertions(+), 355 deletions(-)

diff --git a/c_embedded/schem/pic.pro b/c_embedded/schem/pic.pro @@ -1,4 +1,4 @@ -update=Fri Jan 21 13:58:09 2022 +update=Tue Jan 25 02:02:50 2022 version=1 last_client=kicad [general] @@ -34,7 +34,7 @@ LibDir= [schematic_editor] version=1 PageLayoutDescrFile=layout.kicad_wks -PlotDirectoryName=/home/christos/ +PlotDirectoryName=./ SubpartIdSeparator=0 SubpartFirstId=65 NetFmtName= diff --git a/c_embedded/schem/pic.sch b/c_embedded/schem/pic.sch @@ -47,50 +47,6 @@ F 3 "~" H 4100 5950 50 0001 C CNN 1 0 0 -1 $EndComp $Comp -L Device:C_Small C1 -U 1 1 61E97CC0 -P 4100 3750 -F 0 "C1" H 4192 3796 50 0000 L CNN -F 1 "22pF" H 4192 3705 50 0000 L CNN -F 2 "" H 4100 3750 50 0001 C CNN -F 3 "~" H 4100 3750 50 0001 C CNN - 1 4100 3750 - -1 0 0 -1 -$EndComp -$Comp -L power:GNDREF GND -U 1 1 61EE8AF0 -P 4300 3900 -F 0 "GND" H 4388 3863 50 0000 L CNN -F 1 "GNDREF" H 4305 3727 50 0001 C CNN -F 2 "" H 4300 3900 50 0001 C CNN -F 3 "" H 4300 3900 50 0001 C CNN - 1 4300 3900 - 1 0 0 -1 -$EndComp -$Comp -L Device:C_Small C2 -U 1 1 61ECA409 -P 4500 3750 -F 0 "C2" H 4592 3796 50 0000 L CNN -F 1 "22pF" H 4592 3705 50 0000 L CNN -F 2 "" H 4500 3750 50 0001 C CNN -F 3 "~" H 4500 3750 50 0001 C CNN - 1 4500 3750 - 1 0 0 -1 -$EndComp -$Comp -L Device:Crystal OSC1 -U 1 1 61EB43E4 -P 4300 3550 -F 0 "OSC1" H 4300 3818 50 0000 C CNN -F 1 "8MHz" H 4300 3727 50 0000 C CNN -F 2 "" H 4300 3550 50 0001 C CNN -F 3 "~" H 4300 3550 50 0001 C CNN - 1 4300 3550 - 1 0 0 -1 -$EndComp -$Comp L MCU_Microchip_PIC16:PIC16F877A-IP PIC16F877A-IP1 U 1 1 61E8B28E P 6550 4100 @@ -101,29 +57,6 @@ F 3 "http://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf" H 6550 4100 50 1 6550 4100 1 0 0 -1 $EndComp -Wire Wire Line - 4100 3300 4100 3550 -Wire Wire Line - 4150 3550 4100 3550 -Connection ~ 4100 3550 -Wire Wire Line - 4100 3550 4100 3650 -Wire Wire Line - 4500 3500 4500 3550 -Wire Wire Line - 4450 3550 4500 3550 -Connection ~ 4500 3550 -Wire Wire Line - 4500 3550 4500 3650 -Wire Wire Line - 4300 3900 4100 3900 -Wire Wire Line - 4100 3900 4100 3850 -Wire Wire Line - 4300 3900 4500 3900 -Wire Wire Line - 4500 3900 4500 3850 -Connection ~ 4300 3900 $Comp L Simulation_SPICE:VDC V1 U 1 1 61F2BB51 @@ -175,8 +108,6 @@ Wire Wire Line Wire Wire Line 5450 2150 5450 2500 Wire Wire Line - 5450 2500 5350 2500 -Wire Wire Line 4900 2650 5850 2650 Wire Wire Line 5850 2650 5850 2450 @@ -214,48 +145,10 @@ F 3 "http://www.newhavendisplay.com/specs/NHD-0420H1Z-FSW-GBW-33V3.pdf" H 4500 5 0 1 1 0 $EndComp Wire Wire Line - 4100 3300 5650 3300 -Wire Wire Line - 4500 3500 5650 3500 -Wire Wire Line - 5000 4800 5000 3700 -Wire Wire Line - 5000 3700 5650 3700 -Wire Wire Line - 4900 4800 4900 3800 -Wire Wire Line - 4900 3800 5650 3800 -Wire Wire Line - 4800 4800 4800 3900 -Wire Wire Line - 4800 3900 5650 3900 -Wire Wire Line - 5650 4000 4100 4000 -Wire Wire Line - 4100 4000 4100 4800 -Wire Wire Line - 5650 4100 4000 4100 -Wire Wire Line - 4000 4100 4000 4800 -Wire Wire Line - 5650 4200 3900 4200 -Wire Wire Line - 3900 4200 3900 4800 -Wire Wire Line - 5650 4300 3800 4300 -Wire Wire Line - 3800 4300 3800 4800 -Wire Wire Line - 3600 5200 3350 5200 + 3600 5200 3550 5200 Wire Wire Line 4100 5600 4100 5800 Wire Wire Line - 6000 1950 3200 1950 -Wire Wire Line - 3200 1950 3200 6250 -Wire Wire Line - 3200 6250 4100 6250 -Wire Wire Line 4100 6250 4100 6100 Connection ~ 6000 1950 Wire Wire Line @@ -264,9 +157,7 @@ Wire Wire Line 6550 5600 6550 5700 Connection ~ 6550 5700 Wire Wire Line - 5200 5200 5400 5200 -Wire Wire Line - 5400 5200 5400 6250 + 5200 5200 5300 5200 Connection ~ 4100 6250 Wire Wire Line 4200 5600 4200 5700 @@ -274,37 +165,16 @@ Wire Wire Line 4200 5700 5050 5700 Wire Wire Line 4100 6250 5050 6250 -$Comp -L Device:R_POT_US POT1 -U 1 1 6208C3F4 -P 5050 5950 -F 0 "POT1" H 4983 5996 50 0000 R CNN -F 1 "10kΩ" H 4983 5905 50 0000 R CNN -F 2 "" H 5050 5950 50 0001 C CNN -F 3 "~" H 5050 5950 50 0001 C CNN - 1 5050 5950 - 1 0 0 -1 -$EndComp -Wire Wire Line - 5200 5950 5300 5950 -Wire Wire Line - 5300 5950 5300 5300 -Wire Wire Line - 5300 5300 5200 5300 -Wire Wire Line - 5050 5800 5050 5700 Connection ~ 5050 5700 Wire Wire Line 5050 5700 6550 5700 -Wire Wire Line - 5050 6100 5050 6250 Connection ~ 5050 6250 Wire Wire Line - 5050 6250 5400 6250 + 5050 6250 5300 6250 Wire Wire Line - 3350 6150 6550 6150 + 3550 6150 6550 6150 Wire Wire Line - 3350 5200 3350 6150 + 3550 5200 3550 6150 Connection ~ 6550 6150 Wire Wire Line 6550 6150 6550 6300 @@ -339,49 +209,257 @@ Wire Wire Line Wire Wire Line 7750 2300 8150 2300 Wire Wire Line - 8650 3200 8650 3700 -Connection ~ 8650 3700 -Wire Wire Line - 8450 3700 8650 3700 + 8650 3200 8650 3350 $Comp L Device:LED LED1 U 1 1 61E8F822 -P 8300 3700 -F 0 "LED1" H 8293 3825 50 0000 C CNN -F 1 "LED" H 8293 3826 50 0001 C CNN -F 2 "" H 8300 3700 50 0001 C CNN -F 3 "~" H 8300 3700 50 0001 C CNN - 1 8300 3700 +P 8400 3950 +F 0 "LED1" H 8393 4075 50 0000 C CNN +F 1 "LED" H 8393 4076 50 0001 C CNN +F 2 "" H 8400 3950 50 0001 C CNN +F 3 "~" H 8400 3950 50 0001 C CNN + 1 8400 3950 -1 0 0 1 $EndComp -Wire Wire Line - 8100 3700 8150 3700 -Wire Wire Line - 7450 3700 7800 3700 $Comp L Device:R_US R3 U 1 1 61F053CB -P 7950 3700 -F 0 "R3" H 8018 3746 50 0000 L CNN -F 1 "330Ω" H 8018 3655 50 0000 L CNN -F 2 "" V 7990 3690 50 0001 C CNN -F 3 "~" H 7950 3700 50 0001 C CNN - 1 7950 3700 +P 8000 3950 +F 0 "R3" H 8068 3996 50 0000 L CNN +F 1 "330Ω" H 8068 3905 50 0000 L CNN +F 2 "" V 8040 3940 50 0001 C CNN +F 3 "~" H 8000 3950 50 0001 C CNN + 1 8000 3950 0 -1 -1 0 $EndComp Wire Wire Line 8650 2000 8650 1950 -Wire Wire Line - 8650 3700 8650 6150 $Comp L Switch:SW_Push BTN1 U 1 1 620E2C06 -P 9250 4050 -F 0 "BTN1" H 9250 4243 50 0000 C CNN -F 1 "SW_Push" H 9250 4244 50 0001 C CNN -F 2 "" H 9250 4250 50 0001 C CNN -F 3 "~" H 9250 4250 50 0001 C CNN - 1 9250 4050 +P 8050 3550 +F 0 "BTN1" H 8050 3743 50 0000 C CNN +F 1 "SW_Push" H 8050 3744 50 0001 C CNN +F 2 "" H 8050 3750 50 0001 C CNN +F 3 "~" H 8050 3750 50 0001 C CNN + 1 8050 3550 + 1 0 0 -1 +$EndComp +Wire Wire Line + 3400 1950 3400 6250 +Wire Wire Line + 5450 2500 5350 2500 +$Comp +L Device:C_Small C1 +U 1 1 61E97CC0 +P 4200 2650 +F 0 "C1" H 4292 2696 50 0000 L CNN +F 1 "22pF" H 4292 2605 50 0000 L CNN +F 2 "" H 4200 2650 50 0001 C CNN +F 3 "~" H 4200 2650 50 0001 C CNN + 1 4200 2650 + 1 0 0 1 +$EndComp +$Comp +L Device:C_Small C2 +U 1 1 61ECA409 +P 4200 3350 +F 0 "C2" H 4292 3396 50 0000 L CNN +F 1 "22pF" H 4292 3305 50 0000 L CNN +F 2 "" H 4200 3350 50 0001 C CNN +F 3 "~" H 4200 3350 50 0001 C CNN + 1 4200 3350 + -1 0 0 1 +$EndComp +$Comp +L Device:Crystal OSC1 +U 1 1 61EB43E4 +P 4200 3000 +F 0 "OSC1" H 4200 3268 50 0000 C CNN +F 1 "8MHz" H 4200 3177 50 0000 C CNN +F 2 "" H 4200 3000 50 0001 C CNN +F 3 "~" H 4200 3000 50 0001 C CNN + 1 4200 3000 + 0 -1 -1 0 +$EndComp +$Comp +L power:GNDREF GND +U 1 1 61EE8AF0 +P 3800 3000 +F 0 "GND" H 3888 2963 50 0000 L CNN +F 1 "GNDREF" H 3805 2827 50 0001 C CNN +F 2 "" H 3800 3000 50 0001 C CNN +F 3 "" H 3800 3000 50 0001 C CNN + 1 3800 3000 + 0 1 1 0 +$EndComp +Wire Wire Line + 3800 3000 3850 3000 +Wire Wire Line + 3850 3000 3850 2500 +Wire Wire Line + 3850 2500 4200 2500 +Wire Wire Line + 4200 2500 4200 2550 +Wire Wire Line + 4200 3450 4200 3500 +Wire Wire Line + 4200 3500 3850 3500 +Wire Wire Line + 3850 3500 3850 3000 +Connection ~ 3850 3000 +Wire Wire Line + 4200 3150 4200 3250 +Wire Wire Line + 4200 2850 4200 2750 +Wire Wire Line + 3400 1950 6000 1950 +Wire Wire Line + 3400 6250 4100 6250 +Wire Wire Line + 5300 6250 5300 5200 +Wire Wire Line + 8850 3200 8850 3350 +Wire Wire Line + 8850 3350 8650 3350 +Connection ~ 8650 3350 +Wire Wire Line + 8850 2000 8850 1950 +Wire Wire Line + 8850 1950 8650 1950 +Connection ~ 8650 1950 +Wire Wire Line + 5050 6100 5050 6250 +Wire Wire Line + 5200 5950 5200 5300 +Wire Wire Line + 5050 5800 5050 5700 +$Comp +L Device:R_POT_US POT1 +U 1 1 6208C3F4 +P 5050 5950 +F 0 "POT1" H 4983 5996 50 0000 R CNN +F 1 "10kΩ" H 4983 5905 50 0000 R CNN +F 2 "" H 5050 5950 50 0001 C CNN +F 3 "~" H 5050 5950 50 0001 C CNN + 1 5050 5950 1 0 0 -1 $EndComp +Wire Wire Line + 4200 3250 4650 3250 +Wire Wire Line + 4650 3250 4650 3500 +Wire Wire Line + 4650 3500 5650 3500 +Connection ~ 4200 3250 +Wire Wire Line + 4200 2750 4750 2750 +Wire Wire Line + 4750 2750 4750 3300 +Wire Wire Line + 4750 3300 5650 3300 +Connection ~ 4200 2750 +Wire Wire Line + 7450 3700 7850 3700 +Wire Wire Line + 7850 3700 7850 3550 +Wire Wire Line + 8650 3350 8650 3550 +Connection ~ 8650 3550 +Wire Wire Line + 8650 3550 8650 3950 +Wire Wire Line + 7450 3800 7850 3800 +Wire Wire Line + 7850 3800 7850 3950 +Wire Wire Line + 8550 3950 8650 3950 +Connection ~ 8650 3950 +Wire Wire Line + 8650 3950 8650 6150 +Wire Wire Line + 8600 3550 8650 3550 +$Comp +L Device:R_US R4 +U 1 1 62134942 +P 8450 3550 +F 0 "R4" H 8518 3596 50 0000 L CNN +F 1 "10kΩ" H 8518 3505 50 0000 L CNN +F 2 "" V 8490 3540 50 0001 C CNN +F 3 "~" H 8450 3550 50 0001 C CNN + 1 8450 3550 + 0 -1 -1 0 +$EndComp +Wire Wire Line + 8150 3950 8250 3950 +Wire Wire Line + 8250 3550 8300 3550 +Wire Wire Line + 4500 4800 4500 3700 +Wire Wire Line + 4500 3700 5650 3700 +Wire Wire Line + 4400 4800 4400 3800 +Wire Wire Line + 4400 3800 5650 3800 +Wire Wire Line + 4300 4800 4300 3900 +Wire Wire Line + 4300 3900 5650 3900 +Wire Wire Line + 4200 4800 4200 4000 +Wire Wire Line + 4200 4000 5650 4000 +Wire Wire Line + 4100 4800 4100 4100 +Wire Wire Line + 4100 4100 5650 4100 +Wire Wire Line + 4000 4800 4000 4200 +Wire Wire Line + 4000 4200 5650 4200 +Wire Wire Line + 3900 4800 3900 4300 +Wire Wire Line + 3900 4300 5650 4300 +Wire Wire Line + 3800 4800 3800 4400 +Wire Wire Line + 3800 4400 5650 4400 +Wire Wire Line + 5000 4800 5000 4750 +Wire Wire Line + 5000 4750 5400 4750 +Wire Wire Line + 5400 4750 5400 6000 +Wire Wire Line + 5400 6000 8050 6000 +Wire Wire Line + 8050 6000 8050 4600 +Wire Wire Line + 8050 4600 7450 4600 +Wire Wire Line + 4900 4800 4900 4650 +Wire Wire Line + 4900 4650 5500 4650 +Wire Wire Line + 5500 4650 5500 5900 +Wire Wire Line + 5500 5900 7950 5900 +Wire Wire Line + 7950 5900 7950 4700 +Wire Wire Line + 7950 4700 7450 4700 +Wire Wire Line + 4800 4800 4800 4550 +Wire Wire Line + 4800 4550 5600 4550 +Wire Wire Line + 5600 4550 5600 5800 +Wire Wire Line + 5600 5800 7850 5800 +Wire Wire Line + 7850 5800 7850 4800 +Wire Wire Line + 7850 4800 7450 4800 $EndSCHEMATC diff --git a/c_embedded/schem/pic.sch-bak b/c_embedded/schem/pic.sch-bak @@ -47,50 +47,6 @@ F 3 "~" H 4100 5950 50 0001 C CNN 1 0 0 -1 $EndComp $Comp -L Device:C_Small C1 -U 1 1 61E97CC0 -P 4100 3750 -F 0 "C1" H 4192 3796 50 0000 L CNN -F 1 "22pF" H 4192 3705 50 0000 L CNN -F 2 "" H 4100 3750 50 0001 C CNN -F 3 "~" H 4100 3750 50 0001 C CNN - 1 4100 3750 - -1 0 0 -1 -$EndComp -$Comp -L power:GNDREF GND -U 1 1 61EE8AF0 -P 4300 3900 -F 0 "GND" H 4388 3863 50 0000 L CNN -F 1 "GNDREF" H 4305 3727 50 0001 C CNN -F 2 "" H 4300 3900 50 0001 C CNN -F 3 "" H 4300 3900 50 0001 C CNN - 1 4300 3900 - 1 0 0 -1 -$EndComp -$Comp -L Device:C_Small C2 -U 1 1 61ECA409 -P 4500 3750 -F 0 "C2" H 4592 3796 50 0000 L CNN -F 1 "22pF" H 4592 3705 50 0000 L CNN -F 2 "" H 4500 3750 50 0001 C CNN -F 3 "~" H 4500 3750 50 0001 C CNN - 1 4500 3750 - 1 0 0 -1 -$EndComp -$Comp -L Device:Crystal OSC1 -U 1 1 61EB43E4 -P 4300 3550 -F 0 "OSC1" H 4300 3818 50 0000 C CNN -F 1 "8MHz" H 4300 3727 50 0000 C CNN -F 2 "" H 4300 3550 50 0001 C CNN -F 3 "~" H 4300 3550 50 0001 C CNN - 1 4300 3550 - 1 0 0 -1 -$EndComp -$Comp L MCU_Microchip_PIC16:PIC16F877A-IP PIC16F877A-IP1 U 1 1 61E8B28E P 6550 4100 @@ -101,29 +57,6 @@ F 3 "http://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf" H 6550 4100 50 1 6550 4100 1 0 0 -1 $EndComp -Wire Wire Line - 4100 3300 4100 3550 -Wire Wire Line - 4150 3550 4100 3550 -Connection ~ 4100 3550 -Wire Wire Line - 4100 3550 4100 3650 -Wire Wire Line - 4500 3500 4500 3550 -Wire Wire Line - 4450 3550 4500 3550 -Connection ~ 4500 3550 -Wire Wire Line - 4500 3550 4500 3650 -Wire Wire Line - 4300 3900 4100 3900 -Wire Wire Line - 4100 3900 4100 3850 -Wire Wire Line - 4300 3900 4500 3900 -Wire Wire Line - 4500 3900 4500 3850 -Connection ~ 4300 3900 $Comp L Simulation_SPICE:VDC V1 U 1 1 61F2BB51 @@ -175,8 +108,6 @@ Wire Wire Line Wire Wire Line 5450 2150 5450 2500 Wire Wire Line - 5450 2500 5350 2500 -Wire Wire Line 4900 2650 5850 2650 Wire Wire Line 5850 2650 5850 2450 @@ -214,48 +145,10 @@ F 3 "http://www.newhavendisplay.com/specs/NHD-0420H1Z-FSW-GBW-33V3.pdf" H 4500 5 0 1 1 0 $EndComp Wire Wire Line - 4100 3300 5650 3300 -Wire Wire Line - 4500 3500 5650 3500 -Wire Wire Line - 5000 4800 5000 3700 -Wire Wire Line - 5000 3700 5650 3700 -Wire Wire Line - 4900 4800 4900 3800 -Wire Wire Line - 4900 3800 5650 3800 -Wire Wire Line - 4800 4800 4800 3900 -Wire Wire Line - 4800 3900 5650 3900 -Wire Wire Line - 5650 4000 4100 4000 -Wire Wire Line - 4100 4000 4100 4800 -Wire Wire Line - 5650 4100 4000 4100 -Wire Wire Line - 4000 4100 4000 4800 -Wire Wire Line - 5650 4200 3900 4200 -Wire Wire Line - 3900 4200 3900 4800 -Wire Wire Line - 5650 4300 3800 4300 -Wire Wire Line - 3800 4300 3800 4800 -Wire Wire Line - 3600 5200 3350 5200 + 3600 5200 3550 5200 Wire Wire Line 4100 5600 4100 5800 Wire Wire Line - 6000 1950 3200 1950 -Wire Wire Line - 3200 1950 3200 6250 -Wire Wire Line - 3200 6250 4100 6250 -Wire Wire Line 4100 6250 4100 6100 Connection ~ 6000 1950 Wire Wire Line @@ -264,9 +157,7 @@ Wire Wire Line 6550 5600 6550 5700 Connection ~ 6550 5700 Wire Wire Line - 5200 5200 5400 5200 -Wire Wire Line - 5400 5200 5400 6250 + 5200 5200 5300 5200 Connection ~ 4100 6250 Wire Wire Line 4200 5600 4200 5700 @@ -274,37 +165,16 @@ Wire Wire Line 4200 5700 5050 5700 Wire Wire Line 4100 6250 5050 6250 -$Comp -L Device:R_POT_US POT1 -U 1 1 6208C3F4 -P 5050 5950 -F 0 "POT1" H 4983 5996 50 0000 R CNN -F 1 "10kΩ" H 4983 5905 50 0000 R CNN -F 2 "" H 5050 5950 50 0001 C CNN -F 3 "~" H 5050 5950 50 0001 C CNN - 1 5050 5950 - 1 0 0 -1 -$EndComp -Wire Wire Line - 5200 5950 5300 5950 -Wire Wire Line - 5300 5950 5300 5300 -Wire Wire Line - 5300 5300 5200 5300 -Wire Wire Line - 5050 5800 5050 5700 Connection ~ 5050 5700 Wire Wire Line 5050 5700 6550 5700 -Wire Wire Line - 5050 6100 5050 6250 Connection ~ 5050 6250 Wire Wire Line - 5050 6250 5400 6250 + 5050 6250 5300 6250 Wire Wire Line - 3350 6150 6550 6150 + 3550 6150 6550 6150 Wire Wire Line - 3350 5200 3350 6150 + 3550 5200 3550 6150 Connection ~ 6550 6150 Wire Wire Line 6550 6150 6550 6300 @@ -339,49 +209,221 @@ Wire Wire Line Wire Wire Line 7750 2300 8150 2300 Wire Wire Line - 8650 3200 8650 3700 -Connection ~ 8650 3700 -Wire Wire Line - 8450 3700 8650 3700 + 8650 3200 8650 3350 $Comp L Device:LED LED1 U 1 1 61E8F822 -P 8300 3700 -F 0 "LED1" H 8293 3825 50 0000 C CNN -F 1 "LED" H 8293 3826 50 0001 C CNN -F 2 "" H 8300 3700 50 0001 C CNN -F 3 "~" H 8300 3700 50 0001 C CNN - 1 8300 3700 +P 8400 3950 +F 0 "LED1" H 8393 4075 50 0000 C CNN +F 1 "LED" H 8393 4076 50 0001 C CNN +F 2 "" H 8400 3950 50 0001 C CNN +F 3 "~" H 8400 3950 50 0001 C CNN + 1 8400 3950 -1 0 0 1 $EndComp -Wire Wire Line - 8100 3700 8150 3700 -Wire Wire Line - 7450 3700 7800 3700 $Comp L Device:R_US R3 U 1 1 61F053CB -P 7950 3700 -F 0 "R3" H 8018 3746 50 0000 L CNN -F 1 "330Ω" H 8018 3655 50 0000 L CNN -F 2 "" V 7990 3690 50 0001 C CNN -F 3 "~" H 7950 3700 50 0001 C CNN - 1 7950 3700 +P 8000 3950 +F 0 "R3" H 8068 3996 50 0000 L CNN +F 1 "330Ω" H 8068 3905 50 0000 L CNN +F 2 "" V 8040 3940 50 0001 C CNN +F 3 "~" H 8000 3950 50 0001 C CNN + 1 8000 3950 0 -1 -1 0 $EndComp Wire Wire Line 8650 2000 8650 1950 -Wire Wire Line - 8650 3700 8650 6150 $Comp L Switch:SW_Push BTN1 U 1 1 620E2C06 -P 9800 5200 -F 0 "BTN1" H 9800 5393 50 0000 C CNN -F 1 "SW_Push" H 9800 5394 50 0001 C CNN -F 2 "" H 9800 5400 50 0001 C CNN -F 3 "~" H 9800 5400 50 0001 C CNN - 1 9800 5200 +P 8050 3550 +F 0 "BTN1" H 8050 3743 50 0000 C CNN +F 1 "SW_Push" H 8050 3744 50 0001 C CNN +F 2 "" H 8050 3750 50 0001 C CNN +F 3 "~" H 8050 3750 50 0001 C CNN + 1 8050 3550 + 1 0 0 -1 +$EndComp +Wire Wire Line + 3400 1950 3400 6250 +Wire Wire Line + 5450 2500 5350 2500 +$Comp +L Device:C_Small C1 +U 1 1 61E97CC0 +P 4200 2650 +F 0 "C1" H 4292 2696 50 0000 L CNN +F 1 "22pF" H 4292 2605 50 0000 L CNN +F 2 "" H 4200 2650 50 0001 C CNN +F 3 "~" H 4200 2650 50 0001 C CNN + 1 4200 2650 + 1 0 0 1 +$EndComp +$Comp +L Device:C_Small C2 +U 1 1 61ECA409 +P 4200 3350 +F 0 "C2" H 4292 3396 50 0000 L CNN +F 1 "22pF" H 4292 3305 50 0000 L CNN +F 2 "" H 4200 3350 50 0001 C CNN +F 3 "~" H 4200 3350 50 0001 C CNN + 1 4200 3350 + -1 0 0 1 +$EndComp +$Comp +L Device:Crystal OSC1 +U 1 1 61EB43E4 +P 4200 3000 +F 0 "OSC1" H 4200 3268 50 0000 C CNN +F 1 "8MHz" H 4200 3177 50 0000 C CNN +F 2 "" H 4200 3000 50 0001 C CNN +F 3 "~" H 4200 3000 50 0001 C CNN + 1 4200 3000 + 0 -1 -1 0 +$EndComp +$Comp +L power:GNDREF GND +U 1 1 61EE8AF0 +P 3800 3000 +F 0 "GND" H 3888 2963 50 0000 L CNN +F 1 "GNDREF" H 3805 2827 50 0001 C CNN +F 2 "" H 3800 3000 50 0001 C CNN +F 3 "" H 3800 3000 50 0001 C CNN + 1 3800 3000 + 0 1 1 0 +$EndComp +Wire Wire Line + 3800 3000 3850 3000 +Wire Wire Line + 3850 3000 3850 2500 +Wire Wire Line + 3850 2500 4200 2500 +Wire Wire Line + 4200 2500 4200 2550 +Wire Wire Line + 4200 3450 4200 3500 +Wire Wire Line + 4200 3500 3850 3500 +Wire Wire Line + 3850 3500 3850 3000 +Connection ~ 3850 3000 +Wire Wire Line + 4200 3150 4200 3250 +Wire Wire Line + 4200 2850 4200 2750 +Wire Wire Line + 3400 1950 6000 1950 +Wire Wire Line + 3400 6250 4100 6250 +Wire Wire Line + 5300 6250 5300 5200 +Wire Wire Line + 8850 3200 8850 3350 +Wire Wire Line + 8850 3350 8650 3350 +Connection ~ 8650 3350 +Wire Wire Line + 8850 2000 8850 1950 +Wire Wire Line + 8850 1950 8650 1950 +Connection ~ 8650 1950 +Wire Wire Line + 5050 6100 5050 6250 +Wire Wire Line + 5200 5950 5200 5300 +Wire Wire Line + 5050 5800 5050 5700 +$Comp +L Device:R_POT_US POT1 +U 1 1 6208C3F4 +P 5050 5950 +F 0 "POT1" H 4983 5996 50 0000 R CNN +F 1 "10kΩ" H 4983 5905 50 0000 R CNN +F 2 "" H 5050 5950 50 0001 C CNN +F 3 "~" H 5050 5950 50 0001 C CNN + 1 5050 5950 1 0 0 -1 $EndComp +Wire Wire Line + 4200 3250 4650 3250 +Wire Wire Line + 4650 3250 4650 3500 +Wire Wire Line + 4650 3500 5650 3500 +Connection ~ 4200 3250 +Wire Wire Line + 4200 2750 4750 2750 +Wire Wire Line + 4750 2750 4750 3300 +Wire Wire Line + 4750 3300 5650 3300 +Connection ~ 4200 2750 +Wire Wire Line + 7450 3700 7850 3700 +Wire Wire Line + 7850 3700 7850 3550 +Wire Wire Line + 8650 3350 8650 3550 +Connection ~ 8650 3550 +Wire Wire Line + 8650 3550 8650 3950 +Wire Wire Line + 7450 3800 7850 3800 +Wire Wire Line + 7850 3800 7850 3950 +Wire Wire Line + 8550 3950 8650 3950 +Connection ~ 8650 3950 +Wire Wire Line + 8650 3950 8650 6150 +Wire Wire Line + 8600 3550 8650 3550 +$Comp +L Device:R_US R4 +U 1 1 62134942 +P 8450 3550 +F 0 "R4" H 8518 3596 50 0000 L CNN +F 1 "10kΩ" H 8518 3505 50 0000 L CNN +F 2 "" V 8490 3540 50 0001 C CNN +F 3 "~" H 8450 3550 50 0001 C CNN + 1 8450 3550 + 0 -1 -1 0 +$EndComp +Wire Wire Line + 8150 3950 8250 3950 +Wire Wire Line + 8250 3550 8300 3550 +Wire Wire Line + 4500 4800 4500 3700 +Wire Wire Line + 4500 3700 5650 3700 +Wire Wire Line + 4400 4800 4400 3800 +Wire Wire Line + 4400 3800 5650 3800 +Wire Wire Line + 4300 4800 4300 3900 +Wire Wire Line + 4300 3900 5650 3900 +Wire Wire Line + 4200 4800 4200 4000 +Wire Wire Line + 4200 4000 5650 4000 +Wire Wire Line + 4100 4800 4100 4100 +Wire Wire Line + 4100 4100 5650 4100 +Wire Wire Line + 4000 4800 4000 4200 +Wire Wire Line + 4000 4200 5650 4200 +Wire Wire Line + 3900 4800 3900 4300 +Wire Wire Line + 3900 4300 5650 4300 +Wire Wire Line + 3800 4800 3800 4400 +Wire Wire Line + 3800 4400 5650 4400 $EndSCHEMATC diff --git a/c_embedded/schem/schem.pdf b/c_embedded/schem/schem.pdf Binary files differ. diff --git a/c_embedded/src/main.c b/c_embedded/src/main.c @@ -7,15 +7,15 @@ static __code uint16_t __at (_CONFIG) __configword = _FOSC_HS & _WDTE_OFF & _PWRTE_ON & _LVP_OFF & _WRT_OFF & _BOREN_ON & _CPD_OFF & _CP_OFF; -#define _XTAL_FREQ 16000000 -#define TIMER_INTERNAL_CLK (0 << 5) -#define TIMER_RISING_EDGE (0 << 4) -#define TIMER_PRESCALER_TMR0 (0 << 3) +#define _XTAL_FREQ 16000000 /* Crystal oscillator running at 16MHz */ +#define TIMER_RISING_EDGE (0 << 6) /* Interrupt on rising edge */ +#define TIMER_INTERNAL_CLK (0 << 5) /* Use the CLK0 pin */ +#define TIMER_PRESCALAR_TMR0 (0 << 3) /* Assign prescalar to TMR0 */ /* * The last 3 bits of OPTION_REG indicate the prescalar value. In this case, * 111 indicates a prescalar value of 256. */ -#define TIMER_PRESCALER_256 0b111 +#define TIMER_PRESCALAR_256 0b111 /* * We want 1ms delay @ 16Mhz with 256 prescalar, the formula is: * @@ -24,17 +24,37 @@ static __code uint16_t __at (_CONFIG) __configword = * 256 - ((1 * 16000) / (256 * 4)) = * 256 - 15.625 = ~240 * - * sdcc, there's no overflow here... + * sdcc thinks there's an overflow here (hint: he's wrong)... */ #define TIMER_DELAY (256 - ((1 * (_XTAL_FREQ / 1000)) / (256 * 4))) #define TIMER_REQ_MAX 3 -#define LED1_PORT PORTBbits.RB0 -#define LED1_TRIS TRISBbits.TRISB0 - #define OUTPUT 0 #define INPUT 1 +#define BTN_PORT PORTBbits.RB0 +#define BTN_TRIS TRISBbits.TRISB0 +#define BTN_DEBOUNCE_TIME_MS 20 + +#define LED_PORT PORTBbits.RB1 +#define LED_TRIS TRISBbits.TRISB1 + +#define LCD_RS PORTCbits.RC0 +#define LCD_RW PORTCbits.RC1 +#define LCD_EN PORTCbits.RC2 +#define LCD_PORT_DATA PORTD +#define LCD_SEL_INST 0 +#define LCD_SEL_DATA 1 +#define LCD_CLEAR 0x01 /* Clear screen */ +#define LCD_CURS_ZERO 0x02 /* Set cursor on (0, 0) */ +#define LCD_CURS_INC 0x06 /* Auto-increment cursor */ +#define LCD_CURS_OFF 0x0c /* Hide cursor */ +#define LCD_MODE 0x38 /* 16x2 setup */ +#define LCD_DISPLAY_INIT 0x32 /* Required */ +/* Function macros */ +#define lcd_putc(c) lcd_data(c, LCD_SEL_DATA) +#define lcd_cmd(cmd) lcd_data(cmd, LCD_SEL_INST) + typedef void (*ev_handler)(void); struct timer_req { @@ -43,14 +63,27 @@ struct timer_req { uint32_t cnt; }; +static void delay_ms(uint32_t); static void tmr0_init(void); static int tmr0_set_event(ev_handler, uint32_t); static void tmr0_isr(void) __interrupt; static void led_blink(void); +static void button_debounce(void); +static void lcd_init(void); +static void lcd_data(uint8_t, uint8_t); +static void lcd_puts(const char *); static struct timer_req reqs[TIMER_REQ_MAX]; +static uint32_t timecnt = 0; /* Seconds passed since start */ -void +static void +delay_ms(uint32_t t) +{ + while (t--) + __asm nop __endasm; +} + +static void tmr0_init(void) { struct timer_req *r; @@ -64,18 +97,14 @@ tmr0_init(void) } OPTION_REG = 0; OPTION_REG |= TIMER_INTERNAL_CLK | TIMER_RISING_EDGE | - TIMER_PRESCALER_TMR0 | TIMER_PRESCALER_256; + TIMER_PRESCALAR_TMR0 | TIMER_PRESCALAR_256; TMR0 = TIMER_DELAY; - /* - * Enable, TMR0 Interrupt Enable bit, Global Interrupt Enable bit - * and Peripheral Interrupt Enable bit. - */ - INTCONbits.TMR0IE = 1; - INTCONbits.GIE = 1; - INTCONbits.PEIE = 1; + INTCONbits.TMR0IE = 1; /* TMR0 Interrupt Enable */ + INTCONbits.GIE = 1; /* Global Interrupt Enable */ + INTCONbits.PEIE = 1; /* Peripheral Interrupt Enable */ } -int +static int tmr0_set_event(ev_handler handler, uint32_t rate) { struct timer_req *r; @@ -93,7 +122,7 @@ tmr0_set_event(ev_handler handler, uint32_t rate) return (0); } -void +static void tmr0_isr(void) __interrupt { struct timer_req *r; @@ -111,23 +140,90 @@ tmr0_isr(void) __interrupt } } TMR0 = TIMER_DELAY; - INTCONbits.TMR0IF = 0; + INTCONbits.TMR0IF = 0; /* Clear interrupt flags */ } -void +static void led_blink(void) { - LED1_PORT ^= 1; + LED_PORT ^= 1; + /* + * Increment here since this function is called every 1 sec. + * No need to create another one. + */ + timecnt++; +} + + +static void +button_debounce(void) +{ + static uint16_t cnt = 0; + + /* Button is pressed */ + if (BTN_PORT == 0) { + if (cnt == 0) + cnt++; + cnt = BTN_DEBOUNCE_TIME_MS; + } else if (cnt != 0) + cnt--; +} + +/* FIXME: fix delays */ +static void +lcd_init(void) +{ + LCD_PORT_DATA = 0; + LCD_RS = 0; + LCD_RW = 0; + LCD_EN = 0; + TRISC = OUTPUT; + TRISD = OUTPUT; + + lcd_cmd(LCD_DISPLAY_INIT); + delay_ms(150); + lcd_cmd(LCD_DISPLAY_INIT); + delay_ms(150); + + lcd_cmd(LCD_MODE); + lcd_cmd(LCD_CURS_INC); + lcd_cmd(LCD_CURS_ZERO); + lcd_cmd(LCD_CLEAR); + lcd_cmd(LCD_CURS_OFF); +} + +/* FIXME: fix delays */ +static void +lcd_data(uint8_t c, uint8_t rs) +{ + LCD_RS = rs; + LCD_RW = 0; + LCD_EN = 1; + LCD_PORT_DATA = c; + delay_ms(500); + LCD_EN = 0; +} + +static void +lcd_puts(const char *str) +{ + while (*str != '\0') + lcd_putc(*str++); } void main(void) { tmr0_init(); - tmr0_set_event(&led_blink, 1000); /* blink every 1 sec */ - - LED1_TRIS = OUTPUT; - LED1_PORT = 0; /* off */ + tmr0_set_event(&led_blink, 1000); /* Blink every 1 sec */ + tmr0_set_event(&button_debounce, 1); + lcd_init(); + lcd_cmd(LCD_CURS_ZERO); + lcd_puts("19390133"); + + BTN_TRIS = INPUT; + LED_PORT = 1; /* LED on */ + LED_TRIS = OUTPUT; for (;;) { }