Page 1 of 1

Looking for MikroC book or code example??

Posted: 12 Jan 2024 00:39
by Got_MiKroC
Hello all,
I am very infrequent in playing with PICs - and its been perhaps a few years since my last PIC project.

The project I currently have in mind is one I worked out - with an Arduino yesterday.
But it would be wonderful if I could accomplish it with a PIC12F683

I would like to create a very simple piggyback for an 8-digit 7-segment display - which has a MAX7219 driver.
This would entail the PIC continuously looking at a port for an incoming number via SoftwareSerial at 9600 baud
Then display that number on the 7-segment display

Would anyone know of a MikroC project book which might have a project of this kind?
Or perhaps someone could point me to a code example for reading incoming data via SoftwareSerial?
I've searched through the libstock examples - and so far not found anything.

My first step would be to have the PIC read incoming characters and display them on the PICKiT monitor

If this request is inappropriate - I will understand - and I apologize in advance
Sincere thanks

Re: Looking for MikroC book or code example??

Posted: 15 Jan 2024 12:35
by IvanJeremic
Hi,

I have attached web pages for our boards which use MAX7219, you can find examples (PIC included) and manuals in the links below:
https://www.mikroe.com/serial-7-seg-display-board
https://www.mikroe.com/serial-7-seg-display-2-board
https://www.mikroe.com/serial-7-seg-8-digit-board

Hope this will be of some help.

Regards,

Ivan.

Re: Looking for MikroC book or code example??

Posted: 15 Jan 2024 18:30
by Got_MiKroC
Thank you very much ivan!

I will look at these
Sincere thanks!

Re: Looking for MikroC book or code example??

Posted: 16 Jan 2024 09:13
by IvanJeremic
Glad to be of help.

Regards,

Ivan.

Re: Looking for MikroC book or code example??

Posted: 19 Jan 2024 03:02
by Got_MiKroC
Here is the first iteration of the project
It is working code which has the PIC12F683 driving the 8 digit 7 segment MAX7219 display

The code currently does not have SoftwareSerial.Read functionality yet.

At this point - we simply have the PIC driving the display
After initiation of the MAX7219 - it counts from 0 to 65535

For anyone who might be interested:



// MiKroC - 1/18/2024
// PIC12F683 Driving an 8 digit 7-Segment MAX7219 Diaplsy
// Note: The PIC12F683 does not have Hardware SPI
// So we use MikroC's very nice Software SPI library
//------------------------------------------------------------------------------

// Choose 3 pins on the 12F683 as output pins to drive the MAX7219
sbit Chip_Select at GP0_bit;
sbit SoftSpi_CLK at GP1_bit;
sbit SoftSpi_SDO at GP2_bit;

sbit Chip_Select_Direction at TRISIO0_bit;
sbit SoftSpi_CLK_Direction at TRISIO1_bit;
sbit SoftSpi_SDO_Direction at TRISIO2_bit;

// Init Soft_SPI
Soft_SPI_Init();

// Variables we will use
long i;
long y;
char txt[6];
unsigned char result;

// FUNCTION used to transmit initial setup commands to the MAX7219
void max7219_init1() {
Chip_Select = 0;
Soft_SPI_Write(0x09); // BCD mode for digit decoding
Soft_SPI_Write(0xFF);
Chip_Select = 1;

Chip_Select = 0;
Soft_SPI_Write(0x0A);
Soft_SPI_Write(0x00); // Segment luminosity intensity set to zero because the display is quite bright
Chip_Select = 1;

Chip_Select = 0;
Soft_SPI_Write(0x0B);
Soft_SPI_Write(0x07); // Display refresh
Chip_Select = 1;

Chip_Select = 0;
Soft_SPI_Write(0x0C);
Soft_SPI_Write(0x01); // Turn on the display
Chip_Select = 1;
}

// ********************** MAIN ***********************************************************
void MAIN(){
OSCCON = 117; //Sets internal osc to 8 Mhz (Default) and stable
ADCON0 = 0; // all pins digital
ANSEL = 0; // all pins digital
CMCON0 = 7; // Comparators off.
TRISIO = 8; // 0001000 All GPIO output excpt GP3 which cannot function as output


Chip_Select_Direction = 0; // GP0, GP1, GP2 as outputs
SoftSpi_CLK_Direction = 0;
SoftSpi_SDO_Direction = 0;

// initialize the max7219
max7219_init1();
delay_ms(10);

// Clear all digits
for(i=1; i <= 8; i++){
Chip_Select = 0;
Soft_SPI_Write(i);
Soft_SPI_Write(15); // send x0F to clear each digit
Chip_Select = 1;
}
delay_ms(500);

// Count from 0 to 65535 as numbers to display
for(y = 0; y <= 65535; y++)
{
// Convert the number into a numeric text string
WordToStr(y, txt);

// iterate through characters in the text string and send them to the display
for(i=0; i <= 5; i++){
result = txt - '0';
Chip_Select = 0;
Soft_SPI_Write(5-i); // Send the number for each digit
Soft_SPI_Write(result);
Chip_Select = 1;
delay_ms(5);
}
}

//Do nothing at this point
while(1){
}

}