1. Home
  2. Docs
  3. VSDSquadron Mini DataShee...
  4. Projects
  5. Implementing 2-bit Array Multiplier Using VSDSquadron Mini

Implementing 2-bit Array Multiplier Using VSDSquadron Mini

  • Inputs : Two sets of 2-bit inputs are connected to the GPIO pins of the VSDSquadron Mini for the binary numbers to be multiplied.
  • Outputs : Four LEDs connected to different GPIO pins display the 4-bit multiplication result.
  • The specific GPIO pins used for inputs and outputs should be configured according to the project code, ensuring correct data flow and output display.
#include <ch32v00x.h>

#include <debug.h>
int and_gate(int bit1, int bit2) {

return bit1 & bit2;

}

int xor_gate(int bit1, int bit2) {

return bit1 ^ bit2;

}
void GPIO_Config(void) {

// Example configuration for an input pin

GPIO_InitTypeDef GPIO_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; // Input pin

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // Pull-up input

GPIO_Init(GPIOD, &GPIO_InitStructure);

// Example configuration for an output pin

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // Output pin

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // Push-pull output

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOD, &GPIO_InitStructure);

}
int main(void) {

SystemCoreClockUpdate(); // Update system clock

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); // Configure NVIC

Delay_Init(); // Initialize delay functions

GPIO_Config(); // Configure GPIO

while (1) {

// Assume GPIO_ReadInputDataBit and GPIO_WriteBit are utility functions

// to read input states and write output states, respectively.

// Reading input bits

uint8_t a0 = GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_3);

uint8_t a1 = GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4);

uint8_t b0 = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_3);

uint8_t b1 = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_4);

// Computing partial products

uint8_t p0 = and_gate(a0, b0);

uint8_t p1 = xor_gate(and_gate(a0, b1), and_gate(a1, b0));

// Additional operations for p2, p3 as per the 2-bit multiplication logic

// Displaying results on LEDs

GPIO_WriteBit(GPIOD, GPIO_Pin_2, p0 ? SET : RESET);

// Additional GPIO_WriteBit calls to display p1, p2, p3

}

}

https://drive.google.com/file/d/1FeMuWhDoe-iyqMA1rNgYxU5zoSzB0ILD/view?usp=drivesdk

https://github.com/Vivekchoudhary2/somaiya-riscv