microcontroller-111 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. microcontroller_111/__init__.py +4 -0
  2. microcontroller_111/core.py +25 -0
  3. microcontroller_111/data/01_8051_Timer_0_1_kHz_Square_Wave.txt +24 -0
  4. microcontroller_111/data/02_8051_Timer_1_500_Hz_and_1_kHz_Sequential.txt +47 -0
  5. microcontroller_111/data/03_8051_Hybrid_Waveform_400_Hz_900_Hz.txt +46 -0
  6. microcontroller_111/data/04_8051_UART_Transmit_Name.txt +45 -0
  7. microcontroller_111/data/05_8051_UART_Transmit_Name_and_Roll_Number.txt +45 -0
  8. microcontroller_111/data/06_PIC_Addition_of_Two_8_bit_Numbers.txt +17 -0
  9. microcontroller_111/data/07_PIC_Subtraction_of_Two_8_bit_Numbers.txt +23 -0
  10. microcontroller_111/data/08_PIC_Block_Data_Transfer.txt +33 -0
  11. microcontroller_111/data/09_PIC_Timer_Delay_LED_Toggle.txt +37 -0
  12. microcontroller_111/data/10_PIC_Up_Down_Counter_on_LEDs.txt +45 -0
  13. microcontroller_111/data/11_PIC_Start_Reset_8_bit_Up_Counter.txt +60 -0
  14. microcontroller_111/data/12_PIC_Shifting_LED_LSB_MSB.txt +63 -0
  15. microcontroller_111/data/13_PIC_LCD_Name_and_Roll_Number.txt +67 -0
  16. microcontroller_111/data/14_PIC_LCD_MICROCONTROLLER_LAB_ESE.txt +67 -0
  17. microcontroller_111/data/15_PIC_ADC_Threshold_LED_Control.txt +37 -0
  18. microcontroller_111/data/16_PIC_ADC_Display_Digital_Value.txt +61 -0
  19. microcontroller_111/data/17_PIC_LCD_Counter_00_99.txt +60 -0
  20. microcontroller_111/data/18_PIC_4x4_Keypad_Display_Key_on_LCD.txt +105 -0
  21. microcontroller_111/data/19_PIC_Keypad_Four_Successive_Keys.txt +119 -0
  22. microcontroller_111/data/20_PIC_Keypad_Digit_and_ASCII_Code.txt +118 -0
  23. microcontroller_111/data/21_PIC_Keypad_VALID_FUNCTION.txt +120 -0
  24. microcontroller_111/data/22_PIC_Stepper_Motor_Clockwise.txt +25 -0
  25. microcontroller_111/data/23_PIC_Stepper_Motor_Anticlockwise.txt +25 -0
  26. microcontroller_111/data/24_PIC_Stepper_Motor_Direction_by_Push_Buttons.txt +40 -0
  27. microcontroller_111/data/25_PIC_Stepper_Motor_One_Revolution_CW_then_CCW.txt +46 -0
  28. microcontroller_111/data/26_ARM_LPC2148_Addition_of_Two_32_bit_Numbers.txt +11 -0
  29. microcontroller_111/data/27_ARM_LPC2148_Subtraction_of_Two_32_bit_Numbers.txt +11 -0
  30. microcontroller_111/data/28_ARM_LPC2148_AND_OR_XOR_Operations.txt +14 -0
  31. microcontroller_111/data/29_ARM_LPC2148_7_Segment_Up_Counter_00_99.txt +41 -0
  32. microcontroller_111/data/30_ARM_LPC2148_7_Segment_Down_Counter_99_00.txt +41 -0
  33. microcontroller_111/data/31_ARM_LPC2148_7_Segment_Display_a_Two_Digit_Number.txt +35 -0
  34. microcontroller_111/data/32_ARM_LPC2148_7_Segment_Alternate_Patterns.txt +43 -0
  35. microcontroller_111/data/33_ARM_LPC2148_ADC_Value_on_Serial_Terminal.txt +39 -0
  36. microcontroller_111/data/34_ARM_LPC2148_ADC_Count_and_Voltage_on_Serial_Terminal.txt +37 -0
  37. microcontroller_111/data/35_ARM_LPC2148_ADC_Threshold_LOW_HIGH_on_Serial.txt +40 -0
  38. microcontroller_111/data/36_ARM_LPC2148_ADC_Count_and_Voltage_on_LCD.txt +77 -0
  39. microcontroller_111/data/37_ARM_LPC2148_RTC_Hours_Minutes_Seconds_on_LCD.txt +89 -0
  40. microcontroller_111/data/38_ARM_LPC2148_RTC_Date_and_Time_on_LCD.txt +96 -0
  41. microcontroller_111/data/39_ARM_LPC2148_RTC_Alarm_with_LED.txt +108 -0
  42. microcontroller_111/data/40_ARM_LPC2148_RTC_Time_with_LED_at_30_Seconds.txt +95 -0
  43. microcontroller_111-0.1.0.dist-info/METADATA +24 -0
  44. microcontroller_111-0.1.0.dist-info/RECORD +47 -0
  45. microcontroller_111-0.1.0.dist-info/WHEEL +5 -0
  46. microcontroller_111-0.1.0.dist-info/licenses/LICENSE +3 -0
  47. microcontroller_111-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,4 @@
1
+ from .core import list_files, get_path, read_file, data_dir
2
+
3
+ __all__ = ["list_files", "get_path", "read_file", "data_dir"]
4
+ __version__ = "0.1.0"
@@ -0,0 +1,25 @@
1
+ from importlib.resources import files
2
+ from pathlib import Path
3
+
4
+
5
+ def data_dir() -> Path:
6
+ """Folder where the bundled .txt files live after install."""
7
+ return Path(str(files("microcontroller_111") / "data"))
8
+
9
+
10
+ def list_files() -> list:
11
+ """Names of all bundled .txt files."""
12
+ return sorted(p.name for p in data_dir().iterdir() if p.suffix == ".txt")
13
+
14
+
15
+ def get_path(name: str) -> str:
16
+ """Full filesystem path to one bundled file."""
17
+ path = data_dir() / name
18
+ if not path.exists():
19
+ raise FileNotFoundError(f"{name} not found in {data_dir()}")
20
+ return str(path)
21
+
22
+
23
+ def read_file(name: str) -> str:
24
+ """Contents of one bundled file."""
25
+ return Path(get_path(name)).read_text(encoding="utf-8")
@@ -0,0 +1,24 @@
1
+ #include <reg51.h>
2
+
3
+ sbit wave = P1^0; // Output pin for the square wave
4
+
5
+ void delay_500us(void)
6
+ {
7
+ TH0 = 0xFE; // Load count for 500 us
8
+ TL0 = 0x33;
9
+ TR0 = 1; // Start Timer 0
10
+ while (TF0 == 0); // Poll until the overflow flag is set
11
+ TR0 = 0; // Stop Timer 0
12
+ TF0 = 0; // Clear the overflow flag
13
+ }
14
+
15
+ void main(void)
16
+ {
17
+ TMOD = 0x01; // Timer 0, Mode 1 (16-bit timer)
18
+
19
+ while (1)
20
+ {
21
+ wave = ~wave; // Toggle P1.0
22
+ delay_500us(); // Wait half a period
23
+ }
24
+ }
@@ -0,0 +1,47 @@
1
+ #include <reg51.h>
2
+
3
+ sbit wave = P1^0; // Output pin
4
+
5
+ void delay_1ms(void) // Half period for 500 Hz
6
+ {
7
+ TH1 = 0xFC;
8
+ TL1 = 0x66;
9
+ TR1 = 1; // Start Timer 1
10
+ while (TF1 == 0); // Poll overflow flag
11
+ TR1 = 0; // Stop Timer 1
12
+ TF1 = 0; // Clear flag
13
+ }
14
+
15
+ void delay_500us(void) // Half period for 1 kHz
16
+ {
17
+ TH1 = 0xFE;
18
+ TL1 = 0x33;
19
+ TR1 = 1;
20
+ while (TF1 == 0);
21
+ TR1 = 0;
22
+ TF1 = 0;
23
+ }
24
+
25
+ void main(void)
26
+ {
27
+ unsigned int i;
28
+
29
+ TMOD = 0x10; // Timer 1, Mode 1 (16-bit)
30
+
31
+ while (1)
32
+ {
33
+ // 500 Hz for about 1 second (500 cycles = 1000 half periods)
34
+ for (i = 0; i < 1000; i++)
35
+ {
36
+ wave = ~wave;
37
+ delay_1ms();
38
+ }
39
+
40
+ // 1 kHz for about 1 second (1000 cycles = 2000 half periods)
41
+ for (i = 0; i < 2000; i++)
42
+ {
43
+ wave = ~wave;
44
+ delay_500us();
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,46 @@
1
+ #include <reg51.h>
2
+
3
+ sbit wave = P1^0; // Output pin
4
+
5
+ void half_400Hz(void) // 1.25 ms delay
6
+ {
7
+ TH0 = 0xFB;
8
+ TL0 = 0x80;
9
+ TR0 = 1; // Start Timer 0
10
+ while (TF0 == 0); // Poll overflow flag
11
+ TR0 = 0; // Stop timer
12
+ TF0 = 0; // Clear flag
13
+ }
14
+
15
+ void half_900Hz(void) // 555.6 us delay
16
+ {
17
+ TH0 = 0xFE;
18
+ TL0 = 0x00;
19
+ TR0 = 1;
20
+ while (TF0 == 0);
21
+ TR0 = 0;
22
+ TF0 = 0;
23
+ }
24
+
25
+ void main(void)
26
+ {
27
+ unsigned char i;
28
+
29
+ TMOD = 0x01; // Timer 0, Mode 1 (16-bit)
30
+ wave = 0; // Start LOW
31
+
32
+ while (1)
33
+ {
34
+ for (i = 0; i < 4; i++) // 2 cycles of 400 Hz
35
+ {
36
+ wave = ~wave;
37
+ half_400Hz();
38
+ }
39
+
40
+ for (i = 0; i < 4; i++) // 2 cycles of 900 Hz
41
+ {
42
+ wave = ~wave;
43
+ half_900Hz();
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,45 @@
1
+ #include <reg51.h>
2
+
3
+ void serial_init(void)
4
+ {
5
+ TMOD = 0x20; // Timer 1, Mode 2 (8-bit auto-reload)
6
+ TH1 = 0xFD; // 9600 baud at 11.0592 MHz
7
+ SCON = 0x50; // Mode 1, 8-bit UART, REN enabled
8
+ TR1 = 1; // Start Timer 1
9
+ }
10
+
11
+ void send_char(unsigned char ch)
12
+ {
13
+ SBUF = ch; // Load character into the serial buffer
14
+ while (TI == 0); // Wait until transmission completes
15
+ TI = 0; // Clear transmit flag
16
+ }
17
+
18
+ void send_string(unsigned char *str)
19
+ {
20
+ while (*str != '\0')
21
+ {
22
+ send_char(*str);
23
+ str++;
24
+ }
25
+ }
26
+
27
+ void delay(void)
28
+ {
29
+ unsigned int i, j;
30
+ for (i = 0; i < 500; i++)
31
+ for (j = 0; j < 100; j++);
32
+ }
33
+
34
+ void main(void)
35
+ {
36
+ serial_init();
37
+
38
+ while (1)
39
+ {
40
+ send_string("Ishaan Vaidya");
41
+ send_char('\r'); // Carriage return
42
+ send_char('\n'); // New line
43
+ delay(); // Small gap between repeats
44
+ }
45
+ }
@@ -0,0 +1,45 @@
1
+ #include <reg51.h>
2
+
3
+ void serial_init(void)
4
+ {
5
+ TMOD = 0x20; // Timer 1, Mode 2 (8-bit auto-reload)
6
+ TH1 = 0xFD; // 9600 baud at 11.0592 MHz
7
+ SCON = 0x50; // Mode 1, 8-bit UART, REN enabled
8
+ TR1 = 1; // Start Timer 1
9
+ }
10
+
11
+ void send_char(unsigned char ch)
12
+ {
13
+ SBUF = ch; // Load character into the serial buffer
14
+ while (TI == 0); // Wait for transmission to complete
15
+ TI = 0; // Clear transmit flag
16
+ }
17
+
18
+ void send_string(unsigned char *str)
19
+ {
20
+ while (*str != '\0')
21
+ {
22
+ send_char(*str);
23
+ str++;
24
+ }
25
+ }
26
+
27
+ void delay(void)
28
+ {
29
+ unsigned int i, j;
30
+ for (i = 0; i < 500; i++)
31
+ for (j = 0; j < 100; j++);
32
+ }
33
+
34
+ void main(void)
35
+ {
36
+ serial_init();
37
+
38
+ while (1)
39
+ {
40
+ send_string("Name: Ishaan Vaidya, Roll No: 2024200134");
41
+ send_char('\r'); // Carriage return
42
+ send_char('\n'); // New line
43
+ delay(); // Gap between repeats
44
+ }
45
+ }
@@ -0,0 +1,17 @@
1
+ PROCESSOR 18F4550
2
+ #include <xc.inc>
3
+
4
+ PSECT mycode
5
+
6
+ MOVLW 025H ; W = 25H (first 8-bit value)
7
+ MOVWF 20H, a ; store first value at 20H
8
+
9
+ MOVLW 037H ; W = 37H (second 8-bit value)
10
+ MOVWF 21H, a ; store second value at 21H
11
+
12
+ MOVF 20H, W, a ; W = 25H
13
+ ADDWF 21H, W, a ; W = 25H + 37H = 5CH
14
+ MOVWF 22H, a ; store result at 22H
15
+
16
+ HERE:
17
+ GOTO HERE ; stay here so the result can be observed
@@ -0,0 +1,23 @@
1
+ PROCESSOR 18F4550
2
+ #include <xc.inc>
3
+
4
+ PSECT mycode
5
+
6
+ MOVLW 050H ; W = 50H
7
+ MOVWF 20H, a ; first number A = 50H at 20H
8
+
9
+ MOVLW 030H ; W = 30H
10
+ MOVWF 21H, a ; second number B = 30H at 21H
11
+
12
+ ; ---- Case 1: A - B = 50H - 30H (no borrow) ----
13
+ MOVF 21H, W, a ; W = B = 30H
14
+ SUBWF 20H, W, a ; W = A - W = 50H - 30H = 20H
15
+ MOVWF 22H, a ; store result at 22H
16
+
17
+ ; ---- Case 2: B - A = 30H - 50H (borrow) ----
18
+ MOVF 20H, W, a ; W = A = 50H
19
+ SUBWF 21H, W, a ; W = B - W = 30H - 50H = E0H
20
+ MOVWF 23H, a ; store result at 23H
21
+
22
+ HERE:
23
+ GOTO HERE ; stay here to observe results
@@ -0,0 +1,33 @@
1
+ PROCESSOR 18F4550
2
+ #include <xc.inc>
3
+
4
+ PSECT mycode
5
+
6
+ ; ---- Step 1: put 5 data bytes in the source block (20H-24H) ----
7
+ LFSR 0, 020H ; FSR0 -> 20H
8
+ MOVLW 011H
9
+ MOVWF POSTINC0, a ; 20H = 11H, FSR0 -> 21H
10
+ MOVLW 022H
11
+ MOVWF POSTINC0, a ; 21H = 22H
12
+ MOVLW 033H
13
+ MOVWF POSTINC0, a ; 22H = 33H
14
+ MOVLW 044H
15
+ MOVWF POSTINC0, a ; 23H = 44H
16
+ MOVLW 055H
17
+ MOVWF POSTINC0, a ; 24H = 55H
18
+
19
+ ; ---- Step 2: set up pointers and counter ----
20
+ LFSR 0, 020H ; FSR0 -> source start (20H)
21
+ LFSR 1, 040H ; FSR1 -> destination start (40H)
22
+ MOVLW 5
23
+ MOVWF 30H, a ; counter = 5 bytes, kept at 30H
24
+
25
+ ; ---- Step 3: copy loop ----
26
+ COPY_LOOP:
27
+ MOVF POSTINC0, W, a ; W = source byte, FSR0++
28
+ MOVWF POSTINC1, a ; destination = W, FSR1++
29
+ DECFSZ 30H, F, a ; counter--, skip next if counter = 0
30
+ BRA COPY_LOOP ; repeat until all bytes are copied
31
+
32
+ HERE:
33
+ GOTO HERE
@@ -0,0 +1,37 @@
1
+ #include <xc.h>
2
+
3
+ #define _XTAL_FREQ 20000000UL
4
+
5
+ /* Timer0 delay of 500 ms
6
+ Fosc = 20 MHz -> Timer clock = Fosc/4 = 5 MHz
7
+ Prescaler 1:256 -> 1 tick = 256 / 5 MHz = 51.2 us
8
+ Counts needed = 500 ms / 51.2 us = 9766
9
+ Preload value = 65536 - 9766 = 55770 = 0xD9DA */
10
+ void Timer0_Delay_500ms(void)
11
+ {
12
+ TMR0H = 0xD9; // load high byte first
13
+ TMR0L = 0xDA; // then low byte
14
+ INTCONbits.TMR0IF = 0; // clear overflow flag
15
+ T0CONbits.TMR0ON = 1; // start timer
16
+
17
+ while(INTCONbits.TMR0IF == 0); // wait for overflow
18
+
19
+ T0CONbits.TMR0ON = 0; // stop timer
20
+ INTCONbits.TMR0IF = 0; // clear flag
21
+ }
22
+
23
+ void main(void)
24
+ {
25
+ ADCON1 = 0x0F; // make pins digital
26
+
27
+ TRISB = 0x00; // PORTB = output (LEDs)
28
+ LATB = 0x00; // all LEDs OFF
29
+
30
+ T0CON = 0x07; // 16-bit, internal clock, prescaler 1:256, timer OFF
31
+
32
+ while(1)
33
+ {
34
+ LATBbits.LATB0 = !LATBbits.LATB0; // toggle LED1 (RB0)
35
+ Timer0_Delay_500ms();
36
+ }
37
+ }
@@ -0,0 +1,45 @@
1
+ #include <xc.h>
2
+
3
+ #define _XTAL_FREQ 20000000UL
4
+
5
+ unsigned char count = 0;
6
+
7
+ void main(void)
8
+ {
9
+ ADCON1 = 0x0F; // make PORTA/PORTB pins digital
10
+
11
+ TRISB = 0x00; // PORTB = output (LEDs)
12
+ LATB = 0x00; // all LEDs OFF
13
+
14
+ TRISAbits.TRISA2 = 1; // RA2 = input (SW18, UP)
15
+ TRISAbits.TRISA3 = 1; // RA3 = input (SW19, DOWN)
16
+
17
+ while(1)
18
+ {
19
+ // UP button
20
+ if(PORTAbits.RA2 == 0)
21
+ {
22
+ __delay_ms(30); // debounce
23
+ if(PORTAbits.RA2 == 0)
24
+ {
25
+ count++; // increment count
26
+ LATB = count; // show on LEDs
27
+ while(PORTAbits.RA2 == 0); // wait for release
28
+ __delay_ms(30);
29
+ }
30
+ }
31
+
32
+ // DOWN button
33
+ if(PORTAbits.RA3 == 0)
34
+ {
35
+ __delay_ms(30); // debounce
36
+ if(PORTAbits.RA3 == 0)
37
+ {
38
+ count--; // decrement count
39
+ LATB = count; // show on LEDs
40
+ while(PORTAbits.RA3 == 0); // wait for release
41
+ __delay_ms(30);
42
+ }
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,60 @@
1
+ #include <xc.h>
2
+
3
+ #define _XTAL_FREQ 20000000UL
4
+
5
+ unsigned char count = 0; // 8-bit counter
6
+ unsigned char running = 0; // 1 = counting, 0 = stopped
7
+ unsigned char ticks = 0; // counts 10 ms steps
8
+
9
+ void main(void)
10
+ {
11
+ ADCON1 = 0x0F; // make pins digital
12
+
13
+ TRISB = 0x00; // PORTB = output (LEDs)
14
+ LATB = 0x00; // all LEDs OFF
15
+
16
+ TRISAbits.TRISA2 = 1; // RA2 = input (SW18, START)
17
+ TRISAbits.TRISA3 = 1; // RA3 = input (SW19, RESET)
18
+
19
+ while(1)
20
+ {
21
+ // START button
22
+ if(PORTAbits.RA2 == 0)
23
+ {
24
+ __delay_ms(30); // debounce
25
+ if(PORTAbits.RA2 == 0)
26
+ {
27
+ running = 1; // start counting
28
+ while(PORTAbits.RA2 == 0); // wait for release
29
+ }
30
+ }
31
+
32
+ // RESET button
33
+ if(PORTAbits.RA3 == 0)
34
+ {
35
+ __delay_ms(30); // debounce
36
+ if(PORTAbits.RA3 == 0)
37
+ {
38
+ running = 0; // stop counting
39
+ count = 0x00; // reset count
40
+ ticks = 0;
41
+ LATB = count; // LEDs show 00H
42
+ while(PORTAbits.RA3 == 0); // wait for release
43
+ }
44
+ }
45
+
46
+ // Up-counter: increment every 50 x 10 ms = 500 ms
47
+ if(running == 1)
48
+ {
49
+ __delay_ms(10);
50
+ ticks++;
51
+
52
+ if(ticks >= 50)
53
+ {
54
+ ticks = 0;
55
+ count++; // 00H -> FFH -> 00H ...
56
+ LATB = count; // show count on LEDs
57
+ }
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,63 @@
1
+ #include <xc.h>
2
+
3
+ #define _XTAL_FREQ 20000000UL
4
+
5
+ // LED moves RB0 -> RB7
6
+ void Shift_LSB_to_MSB(void)
7
+ {
8
+ unsigned char led = 0x01; // start at LSB (RB0)
9
+ for(unsigned char i = 0; i < 8; i++)
10
+ {
11
+ LATB = led; // only one LED ON
12
+ __delay_ms(300);
13
+ led = led << 1; // shift left: 01 -> 02 -> 04 ... -> 80
14
+ }
15
+ LATB = 0x00; // all OFF after shifting
16
+ }
17
+
18
+ // LED moves RB7 -> RB0
19
+ void Shift_MSB_to_LSB(void)
20
+ {
21
+ unsigned char led = 0x80; // start at MSB (RB7)
22
+ for(unsigned char i = 0; i < 8; i++)
23
+ {
24
+ LATB = led; // only one LED ON
25
+ __delay_ms(300);
26
+ led = led >> 1; // shift right: 80 -> 40 -> 20 ... -> 01
27
+ }
28
+ LATB = 0x00; // all OFF after shifting
29
+ }
30
+
31
+ void main(void)
32
+ {
33
+ ADCON1 = 0x0F; // make pins digital
34
+
35
+ TRISB = 0x00; // PORTB = output (LEDs)
36
+ LATB = 0x00;
37
+
38
+ TRISAbits.TRISA2 = 1; // RA2 = input (SW18)
39
+ TRISAbits.TRISA3 = 1; // RA3 = input (SW19)
40
+
41
+ while(1)
42
+ {
43
+ if(PORTAbits.RA2 == 0) // SW18 pressed
44
+ {
45
+ __delay_ms(30); // debounce
46
+ if(PORTAbits.RA2 == 0)
47
+ {
48
+ while(PORTAbits.RA2 == 0); // wait for release
49
+ Shift_LSB_to_MSB();
50
+ }
51
+ }
52
+
53
+ if(PORTAbits.RA3 == 0) // SW19 pressed
54
+ {
55
+ __delay_ms(30); // debounce
56
+ if(PORTAbits.RA3 == 0)
57
+ {
58
+ while(PORTAbits.RA3 == 0); // wait for release
59
+ Shift_MSB_to_LSB();
60
+ }
61
+ }
62
+ }
63
+ }
@@ -0,0 +1,67 @@
1
+ #include <xc.h>
2
+
3
+ #define _XTAL_FREQ 20000000UL
4
+
5
+ #define LCD_RS LATAbits.LATA0
6
+ #define LCD_E LATAbits.LATA1
7
+
8
+ void LCD_Command(unsigned char cmd)
9
+ {
10
+ LATB = cmd;
11
+ LCD_RS = 0; // RS = 0 -> command
12
+ LCD_E = 1;
13
+ __delay_ms(2);
14
+ LCD_E = 0; // high-to-low pulse latches data
15
+ __delay_ms(2);
16
+ }
17
+
18
+ void LCD_Data(unsigned char data)
19
+ {
20
+ LATB = data;
21
+ LCD_RS = 1; // RS = 1 -> data (character)
22
+ LCD_E = 1;
23
+ __delay_ms(2);
24
+ LCD_E = 0;
25
+ __delay_ms(2);
26
+ }
27
+
28
+ void LCD_String(const char *str)
29
+ {
30
+ while(*str != '\0') // send characters until end of string
31
+ {
32
+ LCD_Data(*str);
33
+ str++;
34
+ }
35
+ }
36
+
37
+ void LCD_Start(void)
38
+ {
39
+ __delay_ms(20); // LCD power-up delay
40
+ LCD_Command(0x38); // 8-bit mode, 2 lines, 5x7 font
41
+ LCD_Command(0x0C); // display ON, cursor OFF
42
+ LCD_Command(0x01); // clear display
43
+ __delay_ms(5);
44
+ LCD_Command(0x06); // auto-increment cursor
45
+ }
46
+
47
+ void main(void)
48
+ {
49
+ ADCON1 = 0x0F; // make pins digital
50
+
51
+ TRISB = 0x00; // PORTB = LCD data (output)
52
+ TRISAbits.TRISA0 = 0; // RA0 = RS (output)
53
+ TRISAbits.TRISA1 = 0; // RA1 = E (output)
54
+
55
+ LATA = 0x00;
56
+ LATB = 0x00;
57
+
58
+ LCD_Start();
59
+
60
+ LCD_Command(0x80); // line 1, position 1
61
+ LCD_String("ISHAAN VAIDYA");
62
+
63
+ LCD_Command(0xC0); // line 2, position 1
64
+ LCD_String("2024200134");
65
+
66
+ while(1); // keep display
67
+ }
@@ -0,0 +1,67 @@
1
+ #include <xc.h>
2
+
3
+ #define _XTAL_FREQ 20000000UL
4
+
5
+ #define LCD_RS LATAbits.LATA0
6
+ #define LCD_E LATAbits.LATA1
7
+
8
+ void LCD_Command(unsigned char cmd)
9
+ {
10
+ LATB = cmd;
11
+ LCD_RS = 0; // command mode
12
+ LCD_E = 1;
13
+ __delay_ms(2);
14
+ LCD_E = 0;
15
+ __delay_ms(2);
16
+ }
17
+
18
+ void LCD_Data(unsigned char data)
19
+ {
20
+ LATB = data;
21
+ LCD_RS = 1; // data mode
22
+ LCD_E = 1;
23
+ __delay_ms(2);
24
+ LCD_E = 0;
25
+ __delay_ms(2);
26
+ }
27
+
28
+ void LCD_String(const char *str)
29
+ {
30
+ while(*str != '\0')
31
+ {
32
+ LCD_Data(*str);
33
+ str++;
34
+ }
35
+ }
36
+
37
+ void LCD_Start(void)
38
+ {
39
+ __delay_ms(20);
40
+ LCD_Command(0x38); // 8-bit, 2 lines
41
+ LCD_Command(0x0C); // display ON, cursor OFF
42
+ LCD_Command(0x01); // clear display
43
+ __delay_ms(5);
44
+ LCD_Command(0x06); // auto-increment cursor
45
+ }
46
+
47
+ void main(void)
48
+ {
49
+ ADCON1 = 0x0F; // make pins digital
50
+
51
+ TRISB = 0x00; // LCD data
52
+ TRISAbits.TRISA0 = 0; // RS
53
+ TRISAbits.TRISA1 = 0; // E
54
+
55
+ LATA = 0x00;
56
+ LATB = 0x00;
57
+
58
+ LCD_Start();
59
+
60
+ LCD_Command(0x80); // line 1, position 1
61
+ LCD_String("MICROCONTROLLER");
62
+
63
+ LCD_Command(0xC0); // line 2, position 1
64
+ LCD_String("LAB ESE");
65
+
66
+ while(1); // keep display
67
+ }