C

C Circuits

Reverse engineering a 16 character display using an Atmel 328p.

Recently I wanted to expand the functionality of an automated test harness for an embedded device. The device has a 16 character display made of 4 Avago HDLx-2416 Series parts (datasheet). I gutted the device and tapped the display’s pins to my AVR. The AVR reads the LED display’s signal pins and sends the displayed string to the test harness via serial connection. Now the test harness can verify that the device under test’s display is lighting as expected. /* * ScreenScan.cpp * * Created: 6/8/2012 *  Author: BK Turley */ /* port wiring: PB0 – ascii 0 PB1 – […]

C Circuits

Switches and interrupts on a PSoC 1 Microcontroller

I. Introduction / Summary The most practical way for a microcontroller to retrieve input is via interrupt.  The vast majority of modern processors have interrupt functionality.  This functionality allows a processor to work on background tasks while no input has happened. Once input is detected, the processor diverts its attention to react, then returns to where it left off after the interrupt has been serviced. II. Description and Circuit Diagrams An optical encoder is connected to VCC and ground to provide power to its internal emitters, detectors, and squaring circuitry.  The encoders outputs are connected to P1[4] and P1[5] on […]

C

Polling a switch Using a PSoC 1 Microcontroller

     One way for a microcontroller to retrieve input is known as polling.  Polling means repeatedly measuring  a sensors value.  I will describe how to poll a pushbutton switch  and react to its measurement when using a Psoc3 microcontroller.   /* * Filename: switchpolling.c * * Title: Polling a switch with a Psoc microcontroller * * Description: This source code file is used with a Psoc 3 microcontroller to poll a switch. * Upon detecting a change in the switches state, An LCD is updated to display the number of * times the switch has been closed in Hex […]

C

Simple Multi-threaded web server written in C using pthreads

This Multi-threaded web server takes advantage of the posix thread library to enable it it serve multiple files at the same time.  Compile using gcc and run on a linux server. // Multi-Threaded web server using posix pthreads // BK Turley 2011 //this simple web server is capible of serving simple html, jpg, gif & text files //—– Include files ——————————————————— #include <stdio.h> // for printf() #include <stdlib.h> // for exit() #include <string.h> // for strcpy(),strerror() and strlen() #include <fcntl.h> // for file i/o constants #include <sys/stat.h> // for file i/o constants #include <errno.h> /* FOR BSD UNIX/LINUX —————————————————- */ […]

C Code

Simple Example of Multithreading in C Linux

This simple example demonstrates the use of multithreading in the linux environment. This little piece of C code has two threads, a producer thread and a consumer thread. The producer thread generates 600 random numbers, which are passed one at a time to a consumer thread via shared memory. Both threads sum all of the random numbers. The fact that both the producer and consumer have the same sum is proof that the thread are communicating together correctly. /* * File: CS314_P01_BKT.c * Author: BK Turley * */ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> #include <sys/sem.h> […]